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); }
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; }
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; }
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; }
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; }
public static JsonRecorder Record(JsonReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } JsonRecorder recorder = new JsonRecorder(); recorder.WriteFromReader(reader); return recorder; }
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()); }
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); }
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)); }
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); }
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); }
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; }
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; }
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; }
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; }
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); }
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; }
protected override object ImportFromBoolean(ImportContext context, JsonReader reader) { return new byte[] { (reader.ReadBoolean() ? ((byte) 1) : ((byte) 0)) }; }
protected override object ImportFromString(ImportContext context, JsonReader reader) { return this.ImportScalarAsArray(context, reader); }
protected override object ImportFromString(ImportContext context, JsonReader reader) { return this.ReflectImport(context, reader); }
protected override object ImportFromNumber(ImportContext context, JsonReader reader) { return new byte[] { reader.ReadNumber().ToByte() }; }
protected virtual object ImportNull(ImportContext context, JsonReader reader) { reader.Read(); return null; }
protected override object ImportFromString(ImportContext context, JsonReader reader) { return ImporterBase.ReadReturning(reader, new Uri(reader.Text)); }
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(); } }
protected override object ImportFromString(ImportContext context, JsonReader reader) { return this.ImportUnderlyingType(context, reader); }
protected virtual object ImportFromBoolean(ImportContext context, JsonReader reader) { return this.ThrowNotSupported(JsonTokenClass.Boolean); }
protected override object ImportFromBoolean(ImportContext context, JsonReader reader) { return Convert.ChangeType(BooleanObject.Box(reader.ReadBoolean()), base.OutputType); }
internal static object ReadReturning(JsonReader reader, object result) { reader.Read(); return result; }
private object ImportUnderlyingType(ImportContext context, JsonReader reader) { return context.Import(this._underlyingType, reader); }
protected virtual object ImportFromString(ImportContext context, JsonReader reader) { return this.ThrowNotSupported(JsonTokenClass.String); }