Exemple #1
0
        /// <summary>Accepts visitor for <see cref="JsonPrimitive"/> instance.</summary>
        public static void AcceptVisitor(this JsonPrimitive self, IJsonVisitor visitor)
        {
            switch (self.JsonType)
            {
            case JsonType.String:
                visitor.Visit((string)self.Value);
                break;

            case JsonType.Number:
                if (self.Value is double || self.Value is float)
                {
                    visitor.Visit((double)self.Value);
                }
                else
                {
                    visitor.Visit((int)self.Value);
                }
                break;

            case JsonType.Boolean:
                visitor.Visit((bool)self.Value);
                break;

            case JsonType.Default:
                visitor.VisitDefault();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #2
0
        public void Can_rewrite_non_generic_type()
        {
            var json      = Files.ReadTextFile("PrettyType0.json");
            var testClass = RewritePrettyTypeVisitor.Visit(json).ToObject <JsonTestClass>(JsonSerializer);

            Assert.NotNull(testClass);
            Assert.NotNull(testClass.Test0);
            Assert.Null(testClass.Test1);
            Assert.Null(testClass.Test2);
        }
 public T Deserialize <T>(string json)
 {
     if (json == null)
     {
         throw new ArgumentNullException(nameof(json));
     }
     return(_transform.Visit(json).ToObject <T>(_jsonSerializer));
 }
Exemple #4
0
 /// <summary>Accepts visitor for <see cref="JsonPrimitive"/> instance.</summary>
 public static void AcceptVisitor(this JsonPrimitive self, IJsonVisitor visitor)
 {
     switch (self.JsonType)
     {
         case JsonType.String:
             visitor.Visit((string)self.Value);
             break;
         case JsonType.Number:
             if(self.Value is double || self.Value is float)
                 visitor.Visit((double)self.Value);
             else
                 visitor.Visit((int)self.Value);
             break;
         case JsonType.Boolean:
             visitor.Visit((bool)self.Value);
             break;
         case JsonType.Default:
             visitor.VisitDefault();
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
Exemple #5
0
 /// <summary>Accepts visitor for <see cref="JsonArray"/> instance.</summary>
 public static void AcceptVisitor(this JsonArray self, IJsonVisitor visitor)
 {
     visitor.Visit(self);
 }
Exemple #6
0
 /// <summary>Accepts visitor for <see cref="JsonObject"/> instance.</summary>
 public static void AcceptVisitor(this JsonObject self, IJsonVisitor visitor)
 {
     visitor.Visit(self);
 }