jeudi 17 janvier 2019

Get all the properties of a object through reflection in c#

I want to get all the properties of a object through reflection.

As of now I am able to get the properties for a single object like below

PropertyInfo[] propertyInfo = typeof(Foo).GetProperties());

But how to get all the properties if it's a complex object like:-

class A
{
     public string Id { get; set; }
     public string Name { get; set; }
}

class B
{
     public List<A> values {get; set;}
     public string SomeProperty {get; set;}
}

From the above structure how to get all the properties and here I can not cast to specified type as the type is not known.

I have searched for solution but no luck, please guide me if this is possible or not and how to achieve this or is there any better way.

Any





Aucun commentaire:

Enregistrer un commentaire