VB to .NET

ISSUE #2069

<class1> property <class1>.<prop1> was not upgraded.

Description

Some constants or static classes may not have a direct equivalent, because there is no equivalent in the .NET core libraries or because no mapping association exists in the specific version of the VBUC in use.

Recommendations

There is no straightforward solution for this issue because some class properties may not have an equivalent in .NET at all.

The entire set of not-mapped elements requires manual implementation of the missing member. This effort can be handled with one of two VBUC features: stub generation and custom mappings (starting with version 2.2).

The Stub Generation feature will assess the manual effort needed to reach functional equivalence by isolating all not-upgraded class properties in a single source file. For more information please refer to Stub generation.

Custom mappings enable simple class and reference mappings to be defined for projects during migration. This option is available in VBUC versions 2.2 and higher, but is not currently available for ASP migrations. A custom migration allows a reference or type to be replaced by a user defined value.

Sample VB6

PublicSub GetProperty(ByVal PropBag As PropertyBag)

Dim mask AsString

mask = PropBag.ReadProperty("Mask", "none")

MsgBox(mask)

EndSub

Target VB.NET

PublicSub GetProperty(ByRef PropBag As UpgradeStubs.VBRUN_PropertyBag)

'UPGRADE_ISSUE: (2069) PropertyBag method PropBag.ReadProperty was not upgraded.

Dim mask AsString = CStr(PropBag.ReadProperty("Mask", "none"))

MessageBox.Show(mask, Application.ProductName)

EndSub

Expected VB.NET

The final solution will depend on the approach taken and the particulars of the application being migrated.

In this case stub generation was selected, creating for us a VBRUN_PropertyBag class. If desired, we can rename this class using one of Visual Studio's refactor commands. The important part, though is to implement the class. In this case I'll just implement it as a wrapper for a generic Dictionary<K, T>. Once we've defined it, our method will work as intended.

PublicClass VBRUN_PropertyBag

Private bag As System.Collections.Generic.Dictionary(OfString, Object) = New System.Collections.Generic.Dictionary(OfString, Object)

 

PublicFunction ReadProperty(ByVal name AsString, OptionalByVal defaultValue AsObject = Nothing) AsObject

Dim value AsObject

value = defaultValue

bag.TryGetValue(name, value)

Return value

EndFunction

 

PublicSub WriteProperty(ByVal name AsString, ByVal value AsObject, OptionalByVal defaultValue AsObject = Nothing)

If value IsNothingThen

value = defaultValue

EndIf

If (bag.ContainsKey(name)) Then

bag(name) = value

Else

bag.Add(name, value)

EndIf

EndSub

EndClass

 

PublicSub GetProperty(ByRef PropBag As UpgradeStubs.VBRUN_PropertyBag)

Dim mask AsString = CStr(PropBag.ReadProperty("Mask", "none"))

MessageBox.Show(mask, Application.ProductName)

EndSub

Target C#

staticpublicvoid GetProperty(UpgradeStubs.VBRUN_PropertyBag PropBag)

{

//UPGRADE_ISSUE: (2069) PropertyBag method PropBag.ReadProperty was not upgraded.

string mask = Convert.ToString(PropBag.ReadProperty("Mask", "none"));

MessageBox.Show(mask, Application.ProductName);

}

Expected C#

The final solution will depend on the approach taken and the particulars of the application being migrated.

In this case stub generation was selected, creating for us a VBRUN_PropertyBag class. If desired, we can rename this class using one of Visual Studio's refactor commands. The important part, though is to implement the class. In this case I'll just implement it as a wrapper for a generic Dictionary<K, T>. Once we've defined it, our method will work as intended.

publicclassVBRUN_PropertyBag

{

privateDictionary<string, object> bag = newDictionary<string, object>();

 

publicobject ReadProperty(string name, object defaultValue)

{

object value;

if (bag.TryGetValue(name, out value) == false)

{

value = defaultValue;

}

return value;

}

 

publicvoid WriteProperty(string name, object value, object defaultValue)

{

if (value == null) { value = defaultValue; }

if (bag.ContainsKey(name))

{

bag[name] = value;

}

else

{

bag.Add(name, value);

}

}

}

 

staticpublicvoid GetProperty(UpgradeStubs.VBRUN_PropertyBag PropBag)

{

string mask = Convert.ToString(PropBag.ReadProperty("Mask", "none"));

MessageBox.Show(mask, Application.ProductName);

}

 

Talk To An Engineer