I want to remove all properties from an object based off a list.
The reason is in my web service call my response object is rather large I want the ability to allow the client to restrict the properties returned from the object.
For example
/api/movie/1?filter=Name,Id,Gross
public class MovieResponse
{
public string Name {get;set;}
public int Id {get;set;}
public double Gross {get;set;}
public string Director {get;set;}
public Rating Rating {get;set;}
}
I would want to return an object based on the above service call that looked like this
public class MovieResponse
{
public string Name {get;set;}
public int Id {get;set;}
public double Gross {get;set;}
}
I assume if i’m using aspnet or wcf i would hook into the request lifecycle and the very last thing I do before I return the response to the client would be to run my filter/behavior that filters and returns the new object that would deserialized into JSON or XML
If you chose to serialize using JSON, you could create a dictionary, like @Randolf R-F said. The dictionary would then get serialized into an object, if you use Json.NET.
Then, on the other side, deserializing could be done using the MovieResponse class.