Alternative to static property in interface?

S

Sin Jeong-hun

I would like to get a static property of classes through an interface.
But static isn't allowed in interface. The class types are
implementing an interface, and loaded from external assemblies (this
is my plug-in architecture). So, if the property is not static I
should create an instance for each class loaded, and instantiations
could be overheads. The static property is a description of the class
so it needn't be instantiated for all instances. I can get the static
property directly from the class, but then I can't make sure that the
class "implemented" that property. That's why I tried to define the
property in the interface in the first place. Then I thought of
putting them as an Attribute of the class, but again, I cannot make
sure that the class has the Attribute.

What would you think is the best way for this situation? Is there any
good way to make sure that the class has the static property ( as
interface does for non-static properties), or do I have to instantiate
them temporarily in order to use the property? Please give me an
advice, thank you.
 
J

Jon Skeet [C# MVP]

Sin Jeong-hun said:
I would like to get a static property of classes through an interface.
But static isn't allowed in interface. The class types are
implementing an interface, and loaded from external assemblies (this
is my plug-in architecture). So, if the property is not static I
should create an instance for each class loaded, and instantiations
could be overheads. The static property is a description of the class
so it needn't be instantiated for all instances. I can get the static
property directly from the class, but then I can't make sure that the
class "implemented" that property. That's why I tried to define the
property in the interface in the first place. Then I thought of
putting them as an Attribute of the class, but again, I cannot make
sure that the class has the Attribute.

What would you think is the best way for this situation? Is there any
good way to make sure that the class has the static property ( as
interface does for non-static properties), or do I have to instantiate
them temporarily in order to use the property? Please give me an
advice, thank you.

You might want to create two interfaces - one for the plugin, and one
for a plugin *factory*. The factory would allow you to create instances
of the plugin, tell you the description, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top