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

Re: Using reflection to get the class name from a virtual method in an abstract class by Kevin

Kevin
Fri Mar 25 16:53:52 CST 2005

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


Re: Using reflection to get the class name from a virtual method in an abstract class by Mattias

Mattias
Fri Mar 25 18:25:22 CST 2005

Kevin,

> s += {Virtual class name here};

s += GetType().Name;



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Re: Using reflection to get the class name from a virtual method in an abstract class by Kevin

Kevin
Fri Mar 25 19:38:39 CST 2005

Easy enough, thanks Mattias!

Kevin


Re: Using reflection to get the class name from a virtual method in an abstract class by Kevin

Kevin
Mon Mar 28 13:05:05 CST 2005

Thanks again for the help.

Kevin Grigorenko
http://www.myplaceonline.com/