Click here to Skip to main content
15,925,723 members
Home / Discussions / C#
   

C#

 
QuestionImplying method return type Pin
eggie51-Oct-07 17:47
eggie51-Oct-07 17:47 
AnswerRe: Implying method return type Pin
Christian Graus1-Oct-07 17:52
protectorChristian Graus1-Oct-07 17:52 
GeneralRe: Implying method return type Pin
eggie51-Oct-07 18:13
eggie51-Oct-07 18:13 
GeneralRe: Implying method return type Pin
TJoe1-Oct-07 18:41
TJoe1-Oct-07 18:41 
GeneralRe: Implying method return type [modified] Pin
eggie51-Oct-07 19:07
eggie51-Oct-07 19:07 
GeneralRe: Implying method return type Pin
TJoe1-Oct-07 19:35
TJoe1-Oct-07 19:35 
GeneralRe: Implying method return type Pin
eggie51-Oct-07 19:42
eggie51-Oct-07 19:42 
AnswerRe: Implying method return type Pin
TJoe1-Oct-07 20:00
TJoe1-Oct-07 20:00 
You can either create an abstract base class or an interface (from which Category and others would derive). If Category and any possible other classes have common functionality, then you should go with an abstract base class, because you can put that common functionality in there. If you go with an interface, then your classes (e.g. Category) really won't share code.

You won't be able to get the static endpoint_url without creating an instance of Category. Both methods above require an instance of Category. Assuming you are willing to create an instance of Category, the code would be like this:

public Response Create<T>() where T : MyBaseClass {
    T myClass = new T();
    String url = myClass.GetURL();
    // ....
}
  
// ...
  
public abstract class MyBaseClass {
    public abstract String GetURL();
  
    // Other method implementations can go here
}
  
public class Category : MyBaseClass {
    public static string endpoint_url = "/categories";
  
    public override String GetURL() {
        return Category.endpoint_url;
    }
}
  
// Then you can call Create like this, where t is of type Test
Response r = t.Create<Category>();




Take care,
Tom

-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com

GeneralRe: Implying method return type Pin
eggie51-Oct-07 20:10
eggie51-Oct-07 20:10 
GeneralRe: Implying method return type Pin
eggie51-Oct-07 20:57
eggie51-Oct-07 20:57 
GeneralRe: Implying method return type Pin
Pete O'Hanlon1-Oct-07 22:49
mvePete O'Hanlon1-Oct-07 22:49 
GeneralRe: Implying method return type Pin
DavidNohejl1-Oct-07 22:51
DavidNohejl1-Oct-07 22:51 
GeneralRe: Implying method return type Pin
TJoe2-Oct-07 3:17
TJoe2-Oct-07 3:17 
GeneralRe: Implying method return type Pin
TJoe1-Oct-07 19:39
TJoe1-Oct-07 19:39 
GeneralRe: Implying method return type Pin
eggie51-Oct-07 19:51
eggie51-Oct-07 19:51 
AnswerRe: Implying method return type Pin
Pete O'Hanlon1-Oct-07 22:58
mvePete O'Hanlon1-Oct-07 22:58 
GeneralRe: Implying method return type Pin
eggie52-Oct-07 7:04
eggie52-Oct-07 7:04 
GeneralRe: Implying method return type Pin
Pete O'Hanlon2-Oct-07 9:51
mvePete O'Hanlon2-Oct-07 9:51 
QuestionCrysta report help Pin
bttds1-Oct-07 17:19
bttds1-Oct-07 17:19 
QuestionSNMP Help required Pin
Muhammad Nauman Yousuf1-Oct-07 15:38
Muhammad Nauman Yousuf1-Oct-07 15:38 
Questionprocess wont start.... Pin
kb1ibh1-Oct-07 14:26
kb1ibh1-Oct-07 14:26 
AnswerRe: process wont start.... Pin
PIEBALDconsult1-Oct-07 14:29
mvePIEBALDconsult1-Oct-07 14:29 
GeneralRe: process wont start.... Pin
kb1ibh1-Oct-07 14:33
kb1ibh1-Oct-07 14:33 
GeneralRe: process wont start.... Pin
PIEBALDconsult1-Oct-07 14:43
mvePIEBALDconsult1-Oct-07 14:43 
QuestionMore if's? Pin
MasterSharp1-Oct-07 14:08
MasterSharp1-Oct-07 14:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.