- INDEX VB TO NET
- VBUC FEATURES
- LANGUAGE TRANSFORMATIONS
- INTERFACES SUPPORT
- IMPLEMENTING A PROPERTY
Implementing a Property
The same as methods, properties (“get”, “let”, and “set”) from an interface could be implemented by another class. In Visual Basic 6, just as a method, it has to add the keyword Implements and declare the corresponding property with the name <Interface>_<PropertyName> in the class.
A difference between methods and properties is that the later could have just the “get”, “let” or “set” properties or a combination of them. In the implementing class the same kinds of properties must be implemented, which means that if in the interface the property implements the “get” and “let”, in the implementing class both properties must be applied as well.
The upgrading process is very similar to the methods conversion procedure. An interface must be generated, along with the CoClass class with the exposed methods. Moreover, for Visual Basic .NET the property must keep the same name, and the Implements keyword is added to the end with the corresponding property to be implemented.
For C# the changes imply renaming the property from <Interface>_<Property> to <Property>, and the Implements keyword is not needed.
Remember, just as with methods, the signature must be the same as the one from the interface.
Original VB6 code
AnInterface.cls Property Get PhaseName() As String ' Code End Property Property Let PhaseName(ByVal v As String) ' Code End Property AClass.cls Implements AnInterface Property Get AnInterface_PhaseName() As String ' Code End Property Property Let AnInterface_PhaseName(ByVal v As String) ' Code End Property
VBUC resulting VB.NET code
AnInterface.cls Interface AnInterface Property PhaseName As String End Interface Friend Class AnInterface_CoClass Implements AnInterface Public Property PhaseName() As String Implements AnInterface.PhaseName Get ' Code End Get Set(ByVal Value As String) ' Code End Set End Property End Class AClass.cls Friend Class AClass Implements AnInterface Property AnInterface_PhaseName() As String Implements AnInterface.PhaseName 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 PhaseName{ get; set; } } internal class AnInterface_CoClass : AnInterface { public string PhaseName { get { // Code return String.Empty; } set { // Code } } } AClass.cls internal class AClass : AnInterface { public string PhaseName { get { // Code return String.Empty; } set { // Code } } }