I have a class which has a property named properties but that property can have different values. Those are dynamic values coming from somewhere and I need to create a request with a structure of Json which has Customer and properties can have different values. I tried the following:
Customer Class
public class Customer{
public string name {get;set;}
public dynamic properties {get;set;}
}
These properties can be dynamic. For example - This can be the json that I get
1st Example:
"properties":{
"name": "Mark",
"address": {
"city":"paris"
}
}
2nd Example:
"properties":{
"name": "Chris",
"description":"human",
"birth":"1990",
"address": {
"name":"paris"
}
}
Whenever I do properties.address.name, it says it can refer to the null reference. I am not sure if dynamic type is correct. How this should be done in C#. If the property can have different values, what is the approach you take?