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

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
 
K

Kevin Grigorenko

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top