I have a Method that creates List<SomeObject>. The Collection is JSON serialized via JavaScriptSerializer. I am using LINQ’s skip/take to return a subset of the total collection. So, I need to return the size of the total collection to the client as an object (this can’t be calculated on the client side because it only has a subset).
I could hack it. Just, add int TotalSize as a member of SomeObject.
I would rather not repeat this Member N times as I only need it once. I also don’t want to perform some terrible OO by adding a member which doesn’t really belong to the class.
Is there anything else I can do in order to add this new member to my JSON object?
Why not make a complex object?
Then, you simply make your new object and assign the data in the constructor, and your JSON should look like so:
And in code you would just do this: