예제 #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            IArgument target;

            if (reader.TokenType == JsonToken.StartObject)
            {
                JObject jObject = JObject.Load(reader);
                if (jObject["url"] != null)
                {
                    target = new XrefTreeArgument();
                    serializer.Populate(jObject.CreateReader(), target);
                }
                else if (jObject["value"] != null)
                {
                    target = new StringArgument(jObject["value"].Value <string>());
                }
                else
                {
                    throw new JsonSerializationException("Expected XrefTreeArgument or StringArgument.");
                }
            }
            else if (reader.TokenType == JsonToken.String)
            {
                target = new StringArgument(reader.Value.ToString());
            }
            else
            {
                throw new JsonReaderException($"Expected object or string but got {reader.TokenType}.");
            }

            return(target);
        }
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     if (reader.TokenType == JsonToken.StartObject)
     {
         IArgument target;
         var       jObject = JObject.Load(reader);
         if (jObject.Property("url") != null)
         {
             target = new XrefTreeArgument();
         }
         else
         {
             target = new StringArgument();
         }
         serializer.Populate(jObject.CreateReader(), target);
         return(target);
     }
     else
     {
         throw new JsonReaderException("Expected start of object.");
     }
 }