c#: Overriding Static Methods/Vars

Associate
Joined
22 Jul 2004
Posts
230
Location
Nottingham, UK
Say i have a class called CustomModule1 which inherits from an abstract base class called Module.

All 'CustomModules' will be in thier own dll and my main application will load them from a folder at run time.
At this point i wish to store information about the CustomModules by getting their string ModuleName (with is different for each module) without creating an instance of the module (statically).

I can't think of away todo this, as I'm loading the CustomModules as Module types, so the static string ModuleName will have to be defined in the ModuleClass.
I need the CustomModule to override this static variable so it gives its own unique name, but you cannot override static properties or methods.

Any thoughts?
 
That's working cheers.

The only thing is a programmer isn't forced to "overide" it, so the base classes maybe used instead.

Is their any other methods which ensures its overriden like an abstract definition would?
 
I'm gonna stick with the 'new' method.

But being as you mentioned reflection:

Can you create a static method in a class which uses reflection to return the type of that class?

I can do it easily from outside the class, but putting it in a static method is more convenient.
 
Thats what i would use outside the class.

Basically i want this static function in the abstract base class, so I cannot hardcode what type to get, as it depends on what has inherited the base class.
 
Inquisitor said:
If you're calling the static method externally, then you'd have to go through the type itself, in which case typeof() would suffice.

That's what I'm doing at the moment, and it works fine.

But it would be more convenient to have a static method which returns a struct of all the details of that class, including the Type of it in one go.
Its not a major problem, I was just wondering if its possible.
 
Back
Top Bottom