I'm creating API and need to give functionality like partial response. I know that in partial response, client/user need to pass the require parameter in controller method. But my case is little bit different. I need to create partial response based on the parameter name called package
.
For example,
[Serializable]
[DataContract]
public class Class1
{
[DataMember]
public double? prop1 { get; set; }
[DataMember]
public string prop2 { get; set; }
[DataMember]
public DateTime? prop3 { get; set; }
[DataMember]
public double? prop4 { get; set; }
[DataMember]
public double? prop5 { get; set; }
[DataMember]
public double? prop6 { get; set; }
[DataMember]
public double? prop7 { get; set; }
[DataMember]
public double? prop8 { get; set; }
[DataMember]
public double? prop9 { get; set; }
[DataMember]
public double? prop10 { get; set; }
}
So, above Class1
is my base class which is called premium
package
. Now for Gold
package
I want few property from Class1
like prop1
to prop4
. So my code would be something like this.
switch (`package`)
{
case "Premium":
Fill the all properties of class1
break;
case "Gold":
Fill the few properties of class1
break;
case "Silver":
Fill the few properties of class2
break;
default:
//TODO
break;
}
So based on the packages
, I want to return my response. But in response I want to add only those class property which is included in package
. So is there any way to dynamically ignore the class property based on condition?
Even Ignoremember
and JSONIgnore
will solved my problem. But for that I need to create different class for different package
s, that I don't want to do that.
Null
value is acceptable.