예제 #1
0
 protected override object ImportFromObject(ImportContext context, JsonReader reader)
 {
     reader.Read();
     object target = Activator.CreateInstance(base.OutputType);
     INonObjectMemberImporter importer = target as INonObjectMemberImporter;
     while (reader.TokenClass != JsonTokenClass.EndObject)
     {
         string name = reader.ReadMember();
         PropertyDescriptor descriptor = this._properties.Find(name, true);
         if ((descriptor == null) || descriptor.IsReadOnly)
         {
             if ((importer == null) || !importer.Import(context, name, reader))
             {
                 reader.Skip();
             }
         }
         else
         {
             if (this._importers != null)
             {
                 int index = this._properties.IndexOf(descriptor);
                 IObjectMemberImporter importer2 = this._importers[index];
                 if (importer2 != null)
                 {
                     importer2.Import(context, reader, target);
                     continue;
                 }
             }
             descriptor.SetValue(target, context.Import(descriptor.PropertyType, reader));
         }
     }
     return ImporterBase.ReadReturning(reader, target);
 }
예제 #2
0
 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     object obj2;
     try
     {
         Match match = Regex.Match(reader.Text, @"\A \/ Date \( ([0-9]+) \) \/ \z", RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);
         if (match.Success)
         {
             DateTime time;
             try
             {
                 time = UnixTime.ToDateTime((double) (((double) long.Parse(match.Groups[1].Value, NumberStyles.None, CultureInfo.InvariantCulture)) / 1000.0));
             }
             catch (OverflowException exception)
             {
                 throw StringError(exception);
             }
             return ImporterBase.ReadReturning(reader, time);
         }
         obj2 = ImporterBase.ReadReturning(reader, XmlConvert.ToDateTime(reader.Text, XmlDateTimeSerializationMode.Local));
     }
     catch (FormatException exception2)
     {
         throw StringError(exception2);
     }
     return obj2;
 }
예제 #3
0
 private object ImportScalarAsArray(ImportContext context, JsonReader reader)
 {
     Type elementType = base.OutputType.GetElementType();
     Array array = Array.CreateInstance(elementType, 1);
     array.SetValue(context.Import(elementType, reader), 0);
     return array;
 }
예제 #4
0
 protected override object ImportFromNumber(ImportContext context, JsonReader reader)
 {
     object obj2;
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     string text = reader.Text;
     try
     {
         obj2 = ImporterBase.ReadReturning(reader, this.ConvertFromString(text));
     }
     catch (FormatException exception)
     {
         throw this.NumberError(exception, text);
     }
     catch (OverflowException exception2)
     {
         throw this.NumberError(exception2, text);
     }
     return obj2;
 }
예제 #5
0
 protected override object ImportFromNumber(ImportContext context, JsonReader reader)
 {
     double num;
     object obj2;
     string text = reader.Text;
     try
     {
         num = Convert.ToDouble(text, CultureInfo.InvariantCulture);
     }
     catch (FormatException exception)
     {
         throw NumberError(exception, text);
     }
     catch (OverflowException exception2)
     {
         throw NumberError(exception2, text);
     }
     try
     {
         obj2 = ImporterBase.ReadReturning(reader, UnixTime.ToDateTime(num));
     }
     catch (ArgumentException exception3)
     {
         throw NumberError(exception3, text);
     }
     return obj2;
 }
예제 #6
0
 public static JsonRecorder Record(JsonReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     JsonRecorder recorder = new JsonRecorder();
     recorder.WriteFromReader(reader);
     return recorder;
 }
예제 #7
0
 protected override object ImportFromArray(ImportContext context, JsonReader reader)
 {
     reader.Read();
     MemoryStream stream = new MemoryStream();
     Type type = typeof(byte);
     while (reader.TokenClass != JsonTokenClass.EndArray)
     {
         stream.WriteByte((byte) context.Import(type, reader));
     }
     return ImporterBase.ReadReturning(reader, stream.ToArray());
 }
예제 #8
0
 private object ImportArray(ImportContext context, JsonReader reader)
 {
     reader.ReadToken(JsonTokenClass.Array);
     List<object> list = new List<object>();
     while (reader.TokenClass != JsonTokenClass.EndArray)
     {
         list.Add(this.ImportValue(context, reader));
     }
     reader.Read();
     return new ReadOnlyCollection<object>(list);
 }
예제 #9
0
 protected override object ImportFromArray(ImportContext context, JsonReader reader)
 {
     reader.Read();
     ArrayList list = new ArrayList();
     Type elementType = base.OutputType.GetElementType();
     while (reader.TokenClass != JsonTokenClass.EndArray)
     {
         list.Add(context.Import(elementType, reader));
     }
     return ImporterBase.ReadReturning(reader, list.ToArray(elementType));
 }
예제 #10
0
 private object ImportValue(ImportContext context, JsonReader reader)
 {
     if (reader.TokenClass == JsonTokenClass.Object)
     {
         return this.ImportFromObject(context, reader);
     }
     if (reader.TokenClass != JsonTokenClass.Array)
     {
         return context.Import(AnyType.Value, reader);
     }
     return this.ImportArray(context, reader);
 }
예제 #11
0
 public virtual object Import(ImportContext context, JsonReader reader)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     return JsonBuffer.From(reader);
 }
예제 #12
0
 protected override object ImportFromNumber(ImportContext context, JsonReader reader)
 {
     object obj2;
     try
     {
         obj2 = BooleanObject.Box(reader.ReadNumber().ToInt64() != 0L);
     }
     catch (FormatException exception)
     {
         throw new JsonException(string.Format("The JSON Number {0} must be an integer to be convertible to System.Boolean.", reader.Text), exception);
     }
     return obj2;
 }
예제 #13
0
 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     object obj2;
     try
     {
         obj2 = Convert.FromBase64String(reader.ReadString());
     }
     catch (FormatException exception)
     {
         throw new JsonException("Error converting JSON String containing base64-encode data to " + base.OutputType.FullName + ".", exception);
     }
     return obj2;
 }
예제 #14
0
 private object ReflectImport(ImportContext context, JsonReader reader)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     IJsonImportable importable = this.CreateObject();
     importable.Import(context, reader);
     return importable;
 }
예제 #15
0
 protected override object ImportFromObject(ImportContext context, JsonReader reader)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     reader.ReadToken(JsonTokenClass.Object);
     IDictionary<string, object> dictionary = new ExpandoObject();
     while (reader.TokenClass != JsonTokenClass.EndObject)
     {
         dictionary[reader.ReadMember()] = this.ImportValue(context, reader);
     }
     reader.Read();
     return dictionary;
 }
예제 #16
0
 public virtual object Import(ImportContext context, JsonReader reader)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if (!reader.MoveToContent())
     {
         throw new JsonException("Unexpected EOF.");
     }
     if (reader.TokenClass == JsonTokenClass.Null)
     {
         return this.ImportNull(context, reader);
     }
     if (reader.TokenClass == JsonTokenClass.String)
     {
         return this.ImportFromString(context, reader);
     }
     if (reader.TokenClass == JsonTokenClass.Number)
     {
         return this.ImportFromNumber(context, reader);
     }
     if (reader.TokenClass == JsonTokenClass.Boolean)
     {
         return this.ImportFromBoolean(context, reader);
     }
     if (reader.TokenClass == JsonTokenClass.Array)
     {
         return this.ImportFromArray(context, reader);
     }
     if (reader.TokenClass != JsonTokenClass.Object)
     {
         throw new JsonException(string.Format("{0} not expected.", reader.TokenClass));
     }
     return this.ImportFromObject(context, reader);
 }
예제 #17
0
 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     object obj2;
     string s = reader.Text.Trim();
     if (s.Length > 0)
     {
         char c = s[0];
         if ((char.IsDigit(c) || (c == '+')) || (c == '-'))
         {
             throw this.Error(s, null);
         }
     }
     try
     {
         obj2 = ImporterBase.ReadReturning(reader, Enum.Parse(base.OutputType, s, true));
     }
     catch (ArgumentException exception)
     {
         throw this.Error(s, exception);
     }
     return obj2;
 }
예제 #18
0
 protected override object ImportFromBoolean(ImportContext context, JsonReader reader)
 {
     return new byte[] { (reader.ReadBoolean() ? ((byte) 1) : ((byte) 0)) };
 }
예제 #19
0
 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     return this.ImportScalarAsArray(context, reader);
 }
예제 #20
0
 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     return this.ReflectImport(context, reader);
 }
예제 #21
0
 protected override object ImportFromNumber(ImportContext context, JsonReader reader)
 {
     return new byte[] { reader.ReadNumber().ToByte() };
 }
예제 #22
0
 protected virtual object ImportNull(ImportContext context, JsonReader reader)
 {
     reader.Read();
     return null;
 }
예제 #23
0
 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     return ImporterBase.ReadReturning(reader, new Uri(reader.Text));
 }
예제 #24
0
 public virtual void WriteFromReader(JsonReader reader)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if (reader.MoveToContent())
     {
         if (reader.TokenClass == JsonTokenClass.String)
         {
             this.WriteString(reader.Text);
         }
         else if (reader.TokenClass == JsonTokenClass.Number)
         {
             this.WriteNumber(reader.Text);
         }
         else if (reader.TokenClass == JsonTokenClass.Boolean)
         {
             this.WriteBoolean(reader.Text == "true");
         }
         else if (reader.TokenClass == JsonTokenClass.Null)
         {
             this.WriteNull();
         }
         else if (reader.TokenClass == JsonTokenClass.Array)
         {
             this.WriteStartArray();
             reader.Read();
             while (reader.TokenClass != JsonTokenClass.EndArray)
             {
                 this.WriteFromReader(reader);
             }
             this.WriteEndArray();
         }
         else
         {
             if (reader.TokenClass != JsonTokenClass.Object)
             {
                 throw new JsonException(string.Format("{0} not expected.", reader.TokenClass));
             }
             reader.Read();
             this.WriteStartObject();
             while (reader.TokenClass != JsonTokenClass.EndObject)
             {
                 this.WriteMember(reader.ReadMember());
                 this.WriteFromReader(reader);
             }
             this.WriteEndObject();
         }
         reader.Read();
     }
 }
예제 #25
0
 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     return this.ImportUnderlyingType(context, reader);
 }
예제 #26
0
 protected virtual object ImportFromBoolean(ImportContext context, JsonReader reader)
 {
     return this.ThrowNotSupported(JsonTokenClass.Boolean);
 }
예제 #27
0
 protected override object ImportFromBoolean(ImportContext context, JsonReader reader)
 {
     return Convert.ChangeType(BooleanObject.Box(reader.ReadBoolean()), base.OutputType);
 }
예제 #28
0
 internal static object ReadReturning(JsonReader reader, object result)
 {
     reader.Read();
     return result;
 }
예제 #29
0
 private object ImportUnderlyingType(ImportContext context, JsonReader reader)
 {
     return context.Import(this._underlyingType, reader);
 }
예제 #30
0
 protected virtual object ImportFromString(ImportContext context, JsonReader reader)
 {
     return this.ThrowNotSupported(JsonTokenClass.String);
 }