locked
What Types can be used for Class Properties? RRS feed

  • Question

  • Hey all.

    I'm developing a VB.Net desktop app and its made sense to go down the route of having functionality being provided by individual plugins. So I've created a test app to get used to how you implement this using Interfaces and all is going swimmingly, however theres a questions I have.

    I've noticed that when setting up a property not all types are available. Why is that? So for example, if I want my plugin interfaces to provide a Name property:

    ReadOnly Property Name() As String
    is the command I'd use in the Interface. However what I thought would be neat for future use is to have an Icon property that delivers an image to the host app - something like:

    ReadOnly Property Icon() As Bitmap
    but this isn't possible. Does anyone know why this is disallowed? How would you provide this kind of functionality through an Interface?

    Finally, there is one property I would like to implement in the Interface that mentions which type of plugin it is: Input, Output or Share. Is there a way that I can define a custom DataType that will only accept a certain list of values? ie
    Dim myType As MyInputType
    Hope that all makes sense!

    Dan
    Tuesday, December 1, 2009 10:40 PM

Answers

  • Is this an issue of not adding proper imports in the source code file?

    For example you may need to add System.Drawing for Bitmap class.

    Try adding
    Imports System.Drawing
    if not already done.

    prakash...
    • Marked as answer by eryang Wednesday, December 9, 2009 2:48 AM
    Wednesday, December 2, 2009 5:49 AM
  • to accept certain list of values you can use enum
    • Marked as answer by eryang Wednesday, December 9, 2009 2:48 AM
    Wednesday, December 2, 2009 6:02 AM
  • Hi,

    sorry, but i can`t see why your properties won`t work except the fact that you use a property name which is also a class name (Icon) what can cause conflicts.. Take a look at the code below which also has your properties in an interface and it doesn`t show any error (in VB 2005 and 2008).
    If you use a classname as a property name, the best would be to put the name in [] brackets.Instead of a custom datatype i would suggest to just use a class for it.

        Public Class MyDataTypeClass
    
        End Class
        Interface MyInterface
            ReadOnly Property [Name]() As String
            ReadOnly Property [Icon]() As Bitmap
            ReadOnly Property MyDataType() As MyDataTypeClass
        End Interface
        Public Class InterfaceConsument
            Implements MyInterface
    
            Public ReadOnly Property [Icon]() As System.Drawing.Bitmap Implements MyInterface.Icon
                Get
    
                End Get
            End Property
    
            Public ReadOnly Property MyDataType() As MyDataTypeClass Implements MyInterface.MyDataType
                Get
    
                End Get
            End Property
    
            Public ReadOnly Property [Name]() As String Implements MyInterface.Name
                Get
    
                End Get
            End Property
        End Class

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Marked as answer by eryang Wednesday, December 9, 2009 2:48 AM
    Wednesday, December 2, 2009 7:03 AM

All replies

  • Is this an issue of not adding proper imports in the source code file?

    For example you may need to add System.Drawing for Bitmap class.

    Try adding
    Imports System.Drawing
    if not already done.

    prakash...
    • Marked as answer by eryang Wednesday, December 9, 2009 2:48 AM
    Wednesday, December 2, 2009 5:49 AM
  • to accept certain list of values you can use enum
    • Marked as answer by eryang Wednesday, December 9, 2009 2:48 AM
    Wednesday, December 2, 2009 6:02 AM
  • Hi,

    sorry, but i can`t see why your properties won`t work except the fact that you use a property name which is also a class name (Icon) what can cause conflicts.. Take a look at the code below which also has your properties in an interface and it doesn`t show any error (in VB 2005 and 2008).
    If you use a classname as a property name, the best would be to put the name in [] brackets.Instead of a custom datatype i would suggest to just use a class for it.

        Public Class MyDataTypeClass
    
        End Class
        Interface MyInterface
            ReadOnly Property [Name]() As String
            ReadOnly Property [Icon]() As Bitmap
            ReadOnly Property MyDataType() As MyDataTypeClass
        End Interface
        Public Class InterfaceConsument
            Implements MyInterface
    
            Public ReadOnly Property [Icon]() As System.Drawing.Bitmap Implements MyInterface.Icon
                Get
    
                End Get
            End Property
    
            Public ReadOnly Property MyDataType() As MyDataTypeClass Implements MyInterface.MyDataType
                Get
    
                End Get
            End Property
    
            Public ReadOnly Property [Name]() As String Implements MyInterface.Name
                Get
    
                End Get
            End Property
        End Class

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Marked as answer by eryang Wednesday, December 9, 2009 2:48 AM
    Wednesday, December 2, 2009 7:03 AM
  • Hi Dan,
    Are those replies helpful? we will appreciate if you could let us know the latest status.

    Thanks,
    Eric
    Please remember to mark helpful replies as answers and unmark them if they provide no help.
    Monday, December 7, 2009 7:32 AM