how to achieve static method in an interface?
Hello, here is a question for c# gurus...
I am trying to conceptually do this
public interface IContentWebControl
{
static string GetLink();
static string bool IsReachable(int UserId);
}
public MyLoginControl : MyCompany.MyStandardUserControl ,IContentWebControl
{
static string GetLink() {}
static IsReachable(int UserId) {}
// ...
}
public MyCheckOutControl : MyCompany.MyStandardUserControl ,IContentWebControl
{
static string GetLink() {}
static IsReachable(int UserId) {}
// ...
}
This does not work because the methods inside the interface cannot be static. The compiler complains.
Is there a way to achieve the same result by other means?
I also tried to make virtual method in the MyCompany.MyStandardUserControl base class but static methods
are not allowed ;) good try though...
Right now, I am using reflection to scan types that derive from MyCompany.MyStandardUserControl
on application start up and look for a GetLink() method with the right prototype.
This is a start up check that catches the classes that did not implement a GetLink()
method. It works fine and it makes you love System.Reflection but it would be better
at compile time.
Ideas?
CF
|