Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 15th, 2004, 08:36 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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


Reply With Quote
  #2 (permalink)  
Old 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
Default

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.:)
Reply With Quote
  #3 (permalink)  
Old September 23rd, 2004, 07:32 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #4 (permalink)  
Old 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
Default

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.:)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT php:function: call objects non static method polarbear Pro PHP 1 June 6th, 2008 05:39 PM
Web User Control to act on interface shared method rodmcleay General .NET 0 June 4th, 2008 11:51 PM
non-static reports to static html files miamikk ASP.NET 2.0 Basics 0 June 4th, 2007 01:48 PM
Method calls within same class w/Interface gmontanaro C# 0 April 6th, 2006 05:44 PM



All times are GMT -4. The time now is 04:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.