Just out of curiosity - in what way would you plan to actually use this?
a: Since static methods can't be virtual, you can't use inheritance, so you
can't generalise it here and would have to copy it into every class
b: I can only see two ways of actually invoking such a feature at runtime:
directly:
MyClass.ObjectName
through reflection:
PropertyInfo prop = typeof(MyClass).GetProperty("ObjectName",
BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Static);
prop.GetValue(null, null);
In the first instance, you already know (give-or-take aliasing) that the
object is called MyClass
In the second instance (or variants involving being passed a Type or
PropertyInfo object) you call just use the Type's Name property -
e.g.
direct: typeof(MyClass).Name
passed a Type object: type.Name
passed a PropertyInfo object: prop.DeclaringType.Name
passed an object instance: obj.GetType().Name
I'm really just not sure what value your function is adding?
Marc
"ABC" <ab*@abc.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
How to return the class name using static getter from a class?
The base class as:
class abcbase
{
..............
public static string ObjectName
{
get { return ??????????? }
}
}
class def : abcbase
{
.....................
}
class ijk : abcbase
{
.......................
}
I want to return "def" if call as:
string strvalue = def.ObjectName;
I want to return "ijk" if call as:
string strvalue = ijk.ObjectName;
How should I do?