c# - Model class with variable properties -




i have api returning json data response. response answers survey taken. have multiple surveys. each survey have multiple questions can different other surveys. (hope make sense here)

i have created model class response 1 of survey follows :-

public string value1 { get; set; }     public string value2 { get; set; }     public string value3 { get; set; }     public string value4 { get; set; }     public int filesystemobjecttype { get; set; }     public int id { get; set; }     public object someurl1 { get; set; }     public string someurl2 { get; set; }     public string typeid { get; set; }     public string differentvalue1 { get; set; }     public bool differentvalue2 { get; set; }     public list<string> differentvalue3 { get; set; }     public list<string> differentvalue4 { get; set;  

the properties differentvalue1, differentvalue2, differentvalue3 .. questions can different each survey. right survey has 4 questions, other surveys can have different number of questions. rest of properties remain same throughout surveys.

eg. other survey can have model

 public string value1 { get; set; }     public string value2 { get; set; }     public string value3 { get; set; }     public string value4 { get; set; }     public int filesystemobjecttype { get; set; }     public int id { get; set; }     public object someurl1 { get; set; }     public string someurl2 { get; set; }     public string typeid { get; set; }     public string differentvalue1 { get; set; }     public bool differentvalue2 { get; set; } 

is there way can make generic model class properties question can different other properties same?

any appreciated.

sounds me typical scenario inheritance..

create base class properties want have surveys , derive class , add properties individual questions child class.

example:

public class surveybase {     public int id { get; set; }     public string someurl { get; set; }     public string typeid { get; set; }      //... }  public class survey1 : surveybase {     public string myquestion1 { get; set; }     public string myquestion2 { get; set; }      //.. }  public class survey2 : surveybase {     public string otherproperty { get; set; }     public int whatever { get; set; }      //.. } 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -