samedi 11 juin 2022

Iterate over dynamic object fields and get field data type

I have object in dynamic type, and index variable in Int data type. Is it possible to get type of field of dynamic object in given index? For better understanding you can imagine my question like so:

dynamic dynamicObject = ...
var type = GetType(dynamicObject.Fields[index]); // Int, String or another.

I fabricated this code for a better understanding. That's why maybe this code view is a little bit absurd :)

For instance

dynamic dynamicObject = new
{
   Name = "Bla",     
   Age = 2,
   Surname = "Bla Bla"
};
int index = 2;

And I want to get System.String

Thanks in advance :)





Aucun commentaire:

Enregistrer un commentaire