i have small winrt client app online service (azure web service). server sends json encoded object (with potential additional metadata) client , client's responsibility deserialize data classes , forward appropriate handlers.
currently, objects received can deserialized simple
todoitem todo = jsonconvert.deserializeobject<todoitem>(message.content); however, there can multiple types of items received. thinking this:
- i include type info in header serverside, such "content-object: todoitem"
- i define attributes todoitem on client side (see below)
- upon receiving message server, find class using attribute defined.
- i call deserialization method resolved type
(example of attribute mentioned in 2.)
[backendobjecttype="todoitem"] public class todoitem my problem approach type generics in deserialization can't call:
type t = resolvetype(message); jsonconvert.deserializeobject<t>(message.content); i tried finding solutions , getting method info deserializeobject , calling using reflection seemed way go. however, getmethod() not exist in winrt , not able find alternative use retrieve generic version of deserializeobject (as fetching name gives me non-generic overload). don't mind using reflection , getmethod can cache (?) methods , call them every time message received without having resolve every time.
so how achieve latter part and/or there way approach this?
alright, feel not problem @ begin discovered deserializeobject(string, type, jsonserializersettings) overload method. works splendidly. however, still hear feedback on approach. think using attributes way resolve type names reasonable or there better ways? don't want use class names directly though, because don't want risk sort of man-in-the-middle things able initialize whatever.
Comments
Post a Comment