web services - asp.net webservice object manipulation -
possibly not specific webservices, but...
i have webmethod returns:
list<tadpole> mylist = getlist(); return new { data = mylist , count = 5 }; it returns json.
my code checks mylist[x].fishsticks isn't part of tadpole class (so errors). wondering, can add fishsticks attribute mylist somehow avoid error, gets included when return data?
is there perhaps elegant solution doing this?
in example, you'll have add fishsticks property tadpole.
public class tadpole { //.... public int fishsticks { get; set; } } also, why adding .count property json type? wouldn't make more sense .data.count, or return list , skip wrapper entirely?
i haven't checked properties of list<> serialized lately, it's possible it's not included, if that's case make more sense this:
list<tadpole> mylist = getlist(); return new { data = mylist , count = mylist.count }; or, create descendant class overrides .count , adds serialization attribute.
edit
if remember correctly, anonymous/dynamic types internally implemented dictionaries, while classes are, well, not. (btw, anonymous types , dynamic objects bring host of performance , maintenance issues along them.)
if don't want modify tadpole reason, create descendant class:
public class hungrytadpole : tadpole { public int fishsticks { get; set; } } strong typing friend , save many headaches down road.
Comments
Post a Comment