Beispiel #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }
            var token = JToken.Load(reader);
            // if (!(token is JValue))
            //     throw new JsonSerializationException("Token was not a primitive");
            //string s = (string)reader.Value;

            var d = DynamicObj.Parse(token.ToString());

            if (objectType != typeof(DynamicObj))
            {
                var i = Activator.CreateInstance(objectType);
                objectType.GetField("_d").SetValue(i, d._d);

                return(i);
            }
            return(d);
        }