Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class A
- {
- public int AProp { get; set; }
- }
- public class B : A
- {
- public int BProp { get; set; }
- }
- public void TestAction(A a)
- {
- if (!(a is B))
- {
- throw new Exception("Should be B!");
- }
- }
- var setting = GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings;
- setting.TypeNameHandling = TypeNameHandling.All;
- {$type: 'MyNamespace.B, MyAssembly', AProp: 1, BProp: 2}
- var json = @"{$type: 'MyNamespace.B, MyAssembly', AProp: 1, BProp: 2}";
- var objA = JsonConvert.DeserializeObject(json, typeof(A), new JsonSerializerSettings
- {
- TypeNameHandling = TypeNameHandling.None
- });
- var objB = JsonConvert.DeserializeObject(json, typeof(A), new JsonSerializerSettings
- {
- TypeNameHandling = TypeNameHandling.All
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement