Solved

Interface with static members

Posted on 2003-11-17
6
167 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
6 Comments
 
LVL 20

Expert Comment

by:TheAvenger
Comment Utility
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
Comment Utility
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 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
You are welcome. I wish you luck
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now