Here is how you can get property name and value from the dynamic object using C#.
let’s assume the dynamic object as:
dynamic objectDetails = new {“Name” : “Ravindra Naik”, “Age” : 26, “Gender”: “Male”}
Now to fetch all the properties present in “objectDetails” here is what you need to do:
var properties = objectDetails.GetType().GetProperties();
In order to fetch a list of property name and values, here is what you need to do:
foreach(var prop in properties)
{
var propName = prop.Name;
var propValue = objectDetails[propName];
}
Here is how you can get property names and values inside a dynamic object using .NET
Thanks for dropping by !! Feel free to comment to this post or you can also drop me an email at [email protected]