1
Answer

Getting value with Reflection?

Ask a question
kobus_2000

kobus_2000

19y
1.8k
1
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

Answers (1)