public void InnerDeserializeObject(ref object instance, BarfDeserializationArgs readArgs) { var typedInstance = instance == null ? default(T) : (T)instance; InnerDeserialize(ref typedInstance, readArgs); instance = typedInstance; }
/// <summary> /// Deserializes an object of the specified type from <paramref name="input"/>. /// </summary> /// <typeparam name="T">The type of object to deserialize.</typeparam> /// <param name="input">The stream to read from.</param> /// <returns>The deserialized object. <see langword="null"/> values are possible /// if <see langword="null"/> was originally serialized into the stream.</returns> /// <exception cref="ArgumentNullException"> /// <para><paramref name="input"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="ArgumentException"> /// <para><paramref name="input.CanSeek"/> is <see langword="false"/>.</para> /// </exception> public static T Deserialize <T>(Stream input) { ArgumentAssert.IsNotNull(input, "input"); if (!input.CanSeek) { throw new ArgumentException("input.CanSeek must be true", "input"); } var serializer = BarfSerializers.Get <T>(PartFlags.None); var args = new BarfDeserializationArgs(SerializerFactory.GetReader(input)); return(serializer.Deserialize(args)); }
public T Deserialize(BarfDeserializationArgs readArgs) { var value = readArgs.Reader.ReadByte(); if (value == SerializerHeaders.Barf) { var result = default(T); InnerDeserialize(ref result, readArgs); return(result); } else { readArgs.Reader.BaseStream.Seek(-1L, SeekOrigin.Current); object result = CreateEmpty(); _typeSerializer.Value.Deserialize(ref result, new TypeSerializationArgs { Reader = readArgs.Reader, Flags = SerializerFlags.Default }); return((T)result); } }
public static void ReadPart <T>(ref T instance, BarfDeserializationArgs args, PartFlags flags) { if (flags.IsSet(PartFlags.Dynamic)) { var index = args.Reader.ReadVarInt32(); if (index < 0) { instance = default(T); } else { var type = args.TypeTable.GetType(index); var serializer = BarfSerializers.Get(type, flags & ~PartFlags.Dynamic); object obj = instance; serializer.InnerDeserializeObject(ref obj, args); instance = (T)obj; } } else { BarfSerializers.Get <T>(flags).InnerDeserialize(ref instance, args); } }
public object DeserializeObject(BarfDeserializationArgs readArgs) { return(Deserialize(readArgs)); }
protected internal abstract void InnerDeserialize(ref T instance, BarfDeserializationArgs readArgs);
protected internal override void InnerDeserialize(ref T instance, BarfDeserializationArgs readArgs) { _deserializeMethod.Value(ref instance, readArgs); }
public static void ReadPart <T>(T instance, BarfDeserializationArgs args, PartFlags flags) where T : class { ReadPart <T>(ref instance, args, flags); }