G
Guest
Hi,
I have a baseclass (non-static) with some static and some non-static
methods/fields/properties.
In the baseclass in one of the static methods I need to do something like
"
somelogic
....
CallToStaticMethod();
....
somelogic
"
The problem is, that I need to be able to change CallToStaticMethod() in the
derived class and call this instead.
I do not want to copy / paste
"
somelogic
....
CallToStaticMethod();
....
somelogic
"
into the derived class.
Since it is a static, I cannot use on "CallToStaticMethod"
"virtual/override" or "abstract/override", if I use "new" I hide the
"CallToStaticMethod", however, calls in the base-class of course go to the
original CallToStaticMethod
So my workaround for now was to pass the type of the derived class to the
baseclass
StaticMethodOnlyInBaseClass(typeof(DerivedClass));
and in the base class implement something like:
static void StaticMethodOnlyInBaseClass(Type callingType)
{
callingType.GetMethod("CallToStaticMethod").Invoke(null, null);
}
This is quite clumsy...
can anyone think of another way?
Would c# generics help me here?
(Please do not forget that I need to have both, non-static and static members)
If so, how?
Thanks,
I have a baseclass (non-static) with some static and some non-static
methods/fields/properties.
In the baseclass in one of the static methods I need to do something like
"
somelogic
....
CallToStaticMethod();
....
somelogic
"
The problem is, that I need to be able to change CallToStaticMethod() in the
derived class and call this instead.
I do not want to copy / paste
"
somelogic
....
CallToStaticMethod();
....
somelogic
"
into the derived class.
Since it is a static, I cannot use on "CallToStaticMethod"
"virtual/override" or "abstract/override", if I use "new" I hide the
"CallToStaticMethod", however, calls in the base-class of course go to the
original CallToStaticMethod
So my workaround for now was to pass the type of the derived class to the
baseclass
StaticMethodOnlyInBaseClass(typeof(DerivedClass));
and in the base class implement something like:
static void StaticMethodOnlyInBaseClass(Type callingType)
{
callingType.GetMethod("CallToStaticMethod").Invoke(null, null);
}
This is quite clumsy...
can anyone think of another way?
Would c# generics help me here?
(Please do not forget that I need to have both, non-static and static members)
If so, how?
Thanks,