Click here to Skip to main content
15,891,951 members
Home / Discussions / C#
   

C#

 
AnswerRe: hi Pin
Luc Pattyn10-Dec-09 12:04
sitebuilderLuc Pattyn10-Dec-09 12:04 
JokeRe: hi Pin
dan!sh 10-Dec-09 17:51
professional dan!sh 10-Dec-09 17:51 
AnswerRe: hi Pin
bassam eshteba10-Dec-09 12:17
bassam eshteba10-Dec-09 12:17 
GeneralRe: hi Pin
Luc Pattyn10-Dec-09 14:10
sitebuilderLuc Pattyn10-Dec-09 14:10 
QuestionUsing html agility pack Pin
Baeltazor10-Dec-09 11:01
Baeltazor10-Dec-09 11:01 
AnswerRe: Using html agility pack Pin
Ravi Bhavnani10-Dec-09 11:20
professionalRavi Bhavnani10-Dec-09 11:20 
QuestionStatic Constructors/Static Initializers Pin
KnyteHawkk10-Dec-09 10:23
KnyteHawkk10-Dec-09 10:23 
AnswerRe: Static Constructors/Static Initializers [modified] Pin
PIEBALDconsult10-Dec-09 10:51
mvePIEBALDconsult10-Dec-09 10:51 
The base class shouldn't know about the derived classes.
And don't use a HashTable unless you're stuck with .net v1.x

I would likely start by writing a static class that would take the place of the static parts of the base class:

public static class Manager
{
    private static readonly System.Collections.Generic.Dictionary<string,BaseClass> dic ;

    static Manager
    (
    )
    {
        dic = new ... 

        dic [ "link1" ] = new DerivedClass1() ;
        ...
    }

    public static BaseClass
    this
    [
        string Key
    ]
    {
        get { return ( dic [ Key ] ) ; }
    }
}


(Not tested.)


Edit:

KnyteHawkk wrote:
retrieve a class instance based solely on a string


I'd prefer to use an enumeration, but then you have to maintain the enumeration as well. Ideally you could use an Attribute to associate a derived class with an enumerated value and then the manager's constructor can fill its Dictionary from the enumeration. Write a derived class, add it to the enumeration, and the manager gets it automatically. The manager could also be made generic.


Further edit:

As soon as I posted it I began to suspect that static classes can't have indexers, and indeed it seems they can't. I have no idea why, maybe in a future version they will be able to.
GeneralRe: Static Constructors/Static Initializers Pin
KnyteHawkk10-Dec-09 11:16
KnyteHawkk10-Dec-09 11:16 
GeneralRe: Static Constructors/Static Initializers Pin
PIEBALDconsult10-Dec-09 11:45
mvePIEBALDconsult10-Dec-09 11:45 
GeneralRe: Static Constructors/Static Initializers Pin
KnyteHawkk10-Dec-09 11:46
KnyteHawkk10-Dec-09 11:46 
AnswerRe: Static Constructors/Static Initializers Pin
Ian Shlasko10-Dec-09 11:28
Ian Shlasko10-Dec-09 11:28 
GeneralRe: Static Constructors/Static Initializers Pin
PIEBALDconsult10-Dec-09 11:44
mvePIEBALDconsult10-Dec-09 11:44 
GeneralRe: Static Constructors/Static Initializers Pin
Ian Shlasko10-Dec-09 12:14
Ian Shlasko10-Dec-09 12:14 
GeneralRe: Static Constructors/Static Initializers Pin
PIEBALDconsult10-Dec-09 12:41
mvePIEBALDconsult10-Dec-09 12:41 
AnswerRe: Static Constructors/Static Initializers Pin
PIEBALDconsult11-Dec-09 11:05
mvePIEBALDconsult11-Dec-09 11:05 
Questionzedgraph Pin
jashimu10-Dec-09 7:25
jashimu10-Dec-09 7:25 
AnswerRe: zedgraph Pin
Luc Pattyn10-Dec-09 7:32
sitebuilderLuc Pattyn10-Dec-09 7:32 
GeneralRe: zedgraph Pin
jashimu10-Dec-09 8:27
jashimu10-Dec-09 8:27 
Question<key value=""> collection as a parameter in an interface method</key> Pin
Chiman110-Dec-09 5:51
Chiman110-Dec-09 5:51 
GeneralRe: collection as a parameter in an interface method [modified] Pin
Abhinav S10-Dec-09 6:22
Abhinav S10-Dec-09 6:22 
GeneralRe: collection as a parameter in an interface method Pin
Chiman111-Dec-09 17:34
Chiman111-Dec-09 17:34 
QuestionSend a class object to a webservice Pin
Gktony10-Dec-09 5:32
Gktony10-Dec-09 5:32 
AnswerRe: Send a class object to a webservice Pin
hammerstein0510-Dec-09 5:52
hammerstein0510-Dec-09 5:52 
GeneralRe: Send a class object to a webservice Pin
Gktony10-Dec-09 6:08
Gktony10-Dec-09 6: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.