I am working on .net console application, and i have this class which I will Deserialzie a returned json on it:-
public class UdfFields
{
public object udf_pick_34206 { get; set; }
public string udf_pick_34205 { get; set; }
public object udf_pick_34202 { get; set; }
public object udf_mline_35402 { get; set; }
public object udf_pick_34503 { get; set; }
public object udf_pick_34502 { get; set; }
public object udf_pick_35103 { get; set; }
public object udf_pick_35101 { get; set; }
public object udf_pick_29744 { get; set; }
public object udf_sline_35701 { get; set; }
public string udf_pick_35401 { get; set; }
public object udf_pick_29753 { get; set; }
}
but the issue i am facing is that on some environments I will have different names for the public object udf_pick_29744 { get; set; }
property .. for example it can be as follow:-
public object udf_pick_28744 { get; set; }
OR
public object udf_pick_26744 { get; set; }
so to make my code dynamic I define the following inside the appsetting.json
file:-
"Field": "udf_pick_28744",
so can i get the value of the Field from my appsettins.json and dynamically name the property inside the class? and if this is not possible then how i can fix this issue?
Thanks
EDIT
I tired to use JsonProperty
as follow,
public class UdfFields
{
static IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsetting.json", optional: false).Build();
string name = config.GetSection("ServiceDesk").GetSection("field").Value;
public object udf_pick_34206 { get; set; }
public string udf_pick_34205 { get; set; }
public object udf_pick_34202 { get; set; }
public object udf_mline_35402 { get; set; }
public object udf_pick_34503 { get; set; }
public object udf_pick_34502 { get; set; }
public object udf_pick_35103 { get; set; }
public object udf_pick_35101 { get; set; }
public object udf_pick_29744 { get; set; }
public object udf_sline_35701 { get; set; }
public string udf_pick_35401 { get; set; }
public object udf_pick_29753 { get; set; }
[JsonProperty(PropertyName = name)]
public object riskdesc { get; set; }
}
but i got this error:-
An object reference is required for the non-static field, method, or property 'UdfFields.name'