[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Interface with static members

Posted on 2003-11-17
6
Medium Priority
?
178 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
  • 3
  • 2
5 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month19 days, 1 hour left to enroll

834 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