.net - How to check an object deserializable in C#? -


i wanna check object deserializable or not? want check string json can desirializable or not? example :

if(obj.isdeserializable()) { var obj1 = new javascriptserializer().deserialize<object>(cobject); } else {  //dosomething ...} 

how can ?

you can't that. can check if object serializable typeof(t).isserializable. can wrap in try-catch block , operation on object if serialization succeds. javascriptserializer().deserializeobject() succeds casting not javascriptserializer().deserializeobject() throws exception if input includes member definitions not available on type t.


Comments