get the name of a property

  • Thread starter Thread starter tolisss
  • Start date Start date
T

tolisss

Hi is it possible to get a property name like

someMethod(someClass.SomeProperty)=="SomeProperty"
 
tolisss said:
Hi is it possible to get a property name like

someMethod(someClass.SomeProperty)=="SomeProperty"

No. someClass.SomeProperty would always be treated as an expression,
and evaluated rather than treated just as a name.
 
Another solution:
Try Type.GetProperties() to retrieve all properties for a class and iterate
to find your property.

myPropertyInfo = Type.GetType("someClass").GetProperties();
for(int i=0;i<myPropertyInfo.Length;i++)
{
PropertyInfo myPropInfo = (PropertyInfo)myPropertyInfo;
Console.WriteLine("The property name is {0}.",
myPropInfo.Name);
Console.WriteLine("The property type is {0}.",
myPropInfo.PropertyType);
}

I hope it helps.

Lionel.
 
Back
Top