Hi
If I have a class Person eg:
Class Person
{
private int identity;
public int Identity
{
get
return this.identity;
set
this.identity = value;
}
How can I get the value of identity (for example) using Reflection if I use the following type of code.
Person person = new Person();
this.DoSomething(person);
public void DoSomething(object obj)
{
//int identity = ???????;
Console.Writeline("Identity = " + identity);
}
}
I tried using the Type.PropertyInfo and GetValue, but the help documentation is not that clear and I did not manage.
Can anybody help me with an example perhaps.
Thanks.
Kobus
Loading
Andrzej WegierskiPosted Jul 25, 2005, 4:15 AM
You can't get value of private object I think.
To use Reflection begin with Type of Your class as in framework help:
PropertyInfo CurProp = (typeof(Person)).GetProperty("Identity");
int identity = (int)(CurProp.GetValue(null,null));