Question First foray into Interfaces - what Datatypes can be used?

danabnormal

New member
Joined
Dec 1, 2009
Messages
2
Programming Experience
3-5
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:

VB.NET:
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:

VB.NET:
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
VB.NET:
Dim myType As MyInputType
)

Hope that all makes sense!

Dan
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,540
Location
Norway
Programming Experience
10+
ReadOnly Property Icon() As Bitmap

but this isn't possible.
Any accessible type is valid to use with an Interface. Have you referenced System.Drawing assembly? Then if you haven't imported System.Drawing namespace you have to qualify the type, for example "As Drawing.Bitmap" (System namespace is always imported). You are probably working with a Class Library project, which don't reference Drawing by default.
Is there a way that I can define a custom DataType that will only accept a certain list of values?
Enum Statement (Visual Basic)
 

danabnormal

New member
Joined
Dec 1, 2009
Messages
2
Programming Experience
3-5
Fantastic, just what I needed!

Yes, this code was just in a Class Library so the Namespace wasn't listed. And Enum was exactly what I was after. Fair enough it wasn't strictly necessary, but may as well go all out and try to code it properly!

Many thanks for your help, most appreciated!
 
Top Bottom