- INDEX VB TO NET
- VBUC FEATURES
- LANGUAGE TRANSFORMATIONS
- INTERFACES SUPPORT
- IMPLEMENTING A FIELD
Implementing a Field
The other member from an interface that can be implemented is the field. The field in the interface is declared as any other public field, but in the implementing class it must be a property (with get and let/set).
Upgrading to Visual Basic .NET implies converting the field to a property in the interface and keeping it in the class. It means the field in the interface must be converted to a property with a get and set with the same name and type. The property in the class follows the same rules as the properties in the previous section, but additionally in the CoClass class a field is added with the name <Field>_MemberVariable to store the value from the property.
For C#, the rules are similar to Visual Basic .NET; the only difference is the renaming of the property name from <Interface>_<Property> to <Property>.
Original VB6 code
AnInterface.cls Public mPhaseName As String AClass.cls Implements AnInterface Public Property Get AnInterface_mPhaseName() As String ' Code End Property Public Property Let AnInterface_mPhaseName(ByVal v As String) ' Code End Property
VBUC resulting VB.NET code
AnInterface.cls Interface AnInterface Property mPhaseName As String End Interface Friend Class AnInterface_CoClass Implements AnInterface Dim mPhaseName_MemberVariable As String = "" Public Property mPhaseName() As String Implements AnInterface.mPhaseName Get mPhaseName = mPhaseName_MemberVariable End Get Set(ByVal Value As String) mPhaseName_MemberVariable = Value End Set End Property End Class AClass.cls Friend Class AClass Implements AnInterface Public Property AnInterface_mPhaseName() As String Implements AnInterface.mPhaseName Get ' Code End Get Set(ByVal Value As String) ' Code End Set End Property End Class
VBUC resulting C#.NET code
AnInterface.cls interface AnInterface { string mPhaseName{ get; set; } } internal class AnInterface_CoClass : AnInterface { string mPhaseName_MemberVariable = String.Empty; public string mPhaseName { get { return mPhaseName_MemberVariable; } set { mPhaseName_MemberVariable = value; } } } AClass.cls internal class AClass : AnInterface { public string mPhaseName { get { // Code return String.Empty; } set { // Code } } }