|
|
 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|
 |

September 15th, 2004, 08:36 PM
|
|
Authorized User
|
|
Join Date: Jul 2004
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

September 21st, 2004, 12:10 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hello,
you cant have any Static Object (like Methods or <s>Fields</s>) in an interface because there is no implementation in an interface so we cant have instances of an interface and so there is no meaning that we could have a static method in an interface ....
--------------------------------------------
Mehdi.:)
|

September 23rd, 2004, 07:32 PM
|
|
Authorized User
|
|
Join Date: Jul 2004
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That's right, we can't have any static in an interface which was the whole point of my post ;)
I have posted on other list and my approach using reflection seems to be one of the viable approaches.
It works great BTW
|

September 28th, 2004, 08:59 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hmm,yes ...
I had a mistake in my previous post,
we cant use Fields in an interface.
cfouquet,I think you could achieve fields too!!! :D
--------------------------------------------
Mehdi.:)
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |