Using reflection to get the class name from a virtual method in an abstract class

  • Thread starter Thread starter Kevin Grigorenko
  • Start date Start date
K

Kevin Grigorenko

I have an abstract class, call it A, with a virtual function from which
I want to handle the default functionality of that method. However,
that method needs the class name of the runtime type of the subclass.

public abstract class A
{
public virtual string B {
get {
string s = somefunction();
s += {Virtual class name here};
return s;
}
}
}

Therefore, if I have a class C that extends A, I want to be able to
call B on an instance of C and get the value of somefunction() + "C"
(without implementing the B property and deferring to the abstract
virtual property).

Any ideas?

Thanks,
Kevin
 
Quick followup. First, I meant to say virtual property, not function.
Second, the reason I asked is because I can't get to the 'this' type
from an abstract class, so I can't seem to do:

Type virtualType = typeof(this.GetType());

Kevin
 
Back
Top