I have a callback web method that Facebook is calling. Unfortunately, the purpose of the call using this single url is determined solely by the structure of the object (json) that is passed in the Post body. Right now, I am thinking of:
try { Class1 obj1 = JsonConvert.DeserializeObject<Class1>(rawData);
//code to run if data is of Class1 ...
}
catch
{ try { Class2 obj2 = JsonConvert.DeserializeObject<Class2>(rawData);
//code to run if data is of Class2 ...
}
catch
{ Class3 obj3 = JsonConvert.DeserializeObject<Class3>(rawData);
//code to run if data is of Class3...
}
}
Is there a cleaner better way than the above?
DeserializeObject<T>