? Runtime Discovery of Property Name using Reflection..

? Runtime Discovery of Property Name using Reflection..

am 29.09.2007 00:20:18 von k.s.easterly

Simple question I hope.


class A
{
void SomePropertyName
{
set
{
string NameOfThisProperty = ??? // what code here to
get "SomePropertyName" at runtime?
}
}
}

Re: ? Runtime Discovery of Property Name using Reflection..

am 29.09.2007 11:17:28 von Alex Meleta

Hi bigtexan,

A base method is:

Type classAtype = typeof(A);
System.Reflection.PropertyInfo[] properties = classAtype.GetProperties();
properties[...].Name

Regards, Alex
[TechBlog] http://devkids.blogspot.com



> class A
> {
> void SomePropertyName
> {
> set
> {
> string NameOfThisProperty = ??? // what code here to
> get "SomePropertyName" at runtime?
> }
> }
> }

Re: ? Runtime Discovery of Property Name using Reflection..

am 29.09.2007 19:33:22 von k.s.easterly

Thanks.... I found it.

System.Reflection.MethodInfo.GetCurrentMethod().Name.Substri ng(4)

This gets the name of the current property/method etc... durring
runtime. So when the runtime pointer is in the set property
SomePropertyName .. it returns "set_SomePropertyName" .. just trim off
the first 4 chars and your golden.

Gratis.