I would like to know how to set property into a nested class with reflection on Xamarin portable class library.
I am working on a project with reflection on a Xamarin portable class library.
I have this code:
public class Customer
{
public string Name { get; set; }
public string FirstName { get; set; }
public int Id { get; set; }
}
public class Invoice
{
public string Description { get; set; }
public int Id { get; set; }
public Customer Person { get; set; }
//New Edit...
//Clases...
// ... More classes
public OtherClass N-1 {get; set}
public MoreClases N {get;set;}
}
on the other hand I have this function:
public void TestCode()
{
var myCustomer = new Customer()
{
FirstName = "qwerty",
Name = "asdfgh",
Id = 1
};
var myInvoice = new Invoice()
{
Description = "chocos",
Id = 1,
Person = myCustomer,
};
var properties = myInvoice.GetType().GetRuntimeProperties();
foreach (var property in properties)
{
var value = property.GetValue(myInvoice);
if (value != null)
{
if (property.PropertyType.IsGenericParameter)
{
//Have Generic parameters
}
else
{
//How I Know if my class == person???
// EDIT:
// If I Use typeof I must check all clases..
}
}
}
}
When I have the string property and I use (for example) GetRuntimeProperties() this function returns about 8 properties so the question is:
How I know if the property it my class?
Other example: How do I know if the property it is my class?
Thank you
EDIT:
Invoice and Customers are examples. The main idea is use Generics now the typeof is evident.
I would like use reflection for all cases.
Thank you
EDIT 2: I add more code in the example.
I hope that is clear myself.
Thank you.