?
Solved

Interface with static members

Posted on 2003-11-17
6
Medium Priority
?
175 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

765 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