I parse JSON response by Newtonsoft.Json
and have a JTokens
that I whant to dynamicly set to my model properties by custom attribute.
As I saw in the source of the Newtonsoft.Json.dll
, JToken
have an implicit (and explicit) convertion methods for all the types that I needed but it have not inherited from IConvertible
, so I can't use Convert.ChangeType
.
If I will try to set them by reflection like
var jToken = GetJtoken(); //so I have a random JToken
var myInstance = new MyModel();
var myPropInfo = myInstance.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).First();
myPropInfo.SetValue(myInstance, jToken);
Will that works?
Does the PropertyInfo.SetValue
support custom implicit convertion?
If it is not, can I convert them dynamicly somehow?
Aucun commentaire:
Enregistrer un commentaire