Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Interface with static members

Posted on 2003-11-17
6
Medium Priority
?
176 Views
Last Modified: 2010-04-16
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"?
0
Comment
Question by:Thorsell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9762796
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.

0
 

Author Comment

by:Thorsell
ID: 9762933
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.
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 500 total points
ID: 9763051
You can check whether the class implements the intefrace and if yes, use the method you already do use: the GetMethod() and then call it. Unfortunately there is no way to make static members abstract or virtual or members of an interface :-((
0
 

Author Comment

by:Thorsell
ID: 9763083
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
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9763094
You are welcome. I wish you luck
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question