json - Dynamically switch applicable DataContract at runtime? -


can turn data contract attributes off , on dynamically? essentially, i'd 2 data contracts, 1 between 3rd party , app, , 1 between app , client - without having manage 2 dto classes. example, consider mydto:

[datacontract] public class mydto {     [datamember(name = "lame/3rdparty/inbound/key")]     public string mycooloutboundkey { get; set; } } 

i'd deserialize dto servicestack.text:

mydto dto = "{\"lame/3rdparty/inbound/key\":\"coolvalue\"}".fromjson<mydto>(); 

but, i'd serialize assertion true:

assert.areequal("{\"mycooloutboundkey\":\"coolvalue\"}",dto.tojson()); 

the actual object in question has on hundred properties, i'm hoping avoid having create second class allow outbound serialization.

so, there nothing wrong approach, think underestimating power of jsonobject, it's kinda linq json.

i used geo data google maps , map nice little dto:

var jsonobj = jsonfromgooglemaps.fromjson<jsonobject>();  return (     x in jsonobject.get<jsonarrayobjects>("results")     let geo = x.get("geometry")     let loc = geo.get("location")     return new coords     {         lat = x.get<decimal>("lat"),         lng = x.get<decimal>("lng"),     } ).firstordefault(); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -