Link to home
Start Free TrialLog in
Avatar of Thorsell
Thorsell

asked on

Interface with static members

according to the documentation about interfaces it's seems impossible to accomblish this. So I'm wondering if there is some way around this "limitation"?
Avatar of TheAvenger
TheAvenger
Flag of Switzerland image

It depends on what you want to do. You can create an abstract class, make all its members abstract and then inherit from it (instead of implementing the interface). Then you can write a static method with its implementation in the abstract class or you can try to create an instance of the inheriting class and call its method. But then you should know the inheriting class which is probably not your case. This solution can probably hide from the outside world that the method is not actually static, but in reality the working method cannot be static.

Avatar of Thorsell
Thorsell

ASKER

Yes i could do that but I want to make it userfriendly. I also want it to be easy to implement more different interfaces with static members, so a abstract class will not work in my case. Right now I'm using the Type.GetMethod() with bindingFlag static to determine wheter the static method is implemented or not.
In my case there is a bunch of dll:s located in directory and I want to be able to determine what object that should be created, based on the return value of a static method on all classes that implements a specific interface.
ASKER CERTIFIED SOLUTION
Avatar of TheAvenger
TheAvenger
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
crap, then I must stick to my old solution =(
I'll keep this thread open alittle longer to see if someone else can come up with any good ideas.
Thanks for your time anyway
You are welcome. I wish you luck