? Runtime Discovery of Property Name using Reflection..

  • Thread starter Thread starter bigtexan
  • Start date Start date
B

bigtexan

Simple question I hope.


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

System.Reflection.MethodInfo.GetCurrentMethod().Name.Substring(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.
 
Back
Top