/// <summary> /// Writes a value without including type information. /// </summary> /// <param name="value">The value to write.</param> /// <param name="stream">The stream to write to.</param> /// <param name="nullable">Whether or not the value can be null.</param> /// <returns>A task that represents the asynchronous write operation.</returns> public async Task WriteValueAsync(object value, Stream stream, bool nullable) { if (value == null) { if (!nullable) { throw new IOException("Unexpected null value when nullable is false"); } await WriteValueFlagNullAsync(stream).ConfigureAwait(false); return; } var valueType = value.GetType(); var serializer = _registry.GetSerializerFor(valueType); await serializer.WriteValueAsync(value, stream, this, nullable).ConfigureAwait(false); }
/// <summary> /// Reads only the value for a specific type <typeparamref name="T"/>. /// </summary> /// <param name="stream">The GraphBinary data to parse.</param> /// <param name="nullable">Whether or not the value can be null.</param> /// <typeparam name="T">The type of the object to read.</typeparam> /// <returns>The read value.</returns> public async Task <object> ReadValueAsync <T>(Stream stream, bool nullable) { var typedSerializer = _registry.GetSerializerFor(typeof(T)); return(await typedSerializer.ReadValueAsync(stream, this, nullable).ConfigureAwait(false)); }