/// <summary> /// Converts the BinaryData to the specified type. /// </summary> /// <typeparam name="T">The type that the data should be /// converted to.</typeparam> /// <param name="data">The BinaryData instance.</param> /// <param name="serializer">The serializer to use /// when deserializing the data.</param> ///<returns>The data converted to the specified type.</returns> public static T As <T>( this BinaryData data, ObjectSerializer serializer) => data.AsAsync <T>(serializer, false).EnsureCompleted();
/// <summary> /// Converts the BinaryData to the specified type. /// </summary> /// <typeparam name="T">The type that the data should be /// converted to.</typeparam> /// <param name="data">The BinaryData instance.</param> /// <param name="serializer">The serializer to use /// when deserializing the data.</param> ///<returns>The data cast to the specified type. If the cast cannot ///be performed, an <see cref="InvalidCastException"/> will be ///thrown.</returns> /// TODO - add cancellation token support /// once ObjectSerializer.DeserializeAsync adds it. public static async ValueTask <T> AsAsync <T>( this BinaryData data, ObjectSerializer serializer) => await data.AsAsync <T>(serializer, true).ConfigureAwait(false);
/// <summary> /// Creates a BinaryData instance from the specified data using /// the specified type. /// </summary> /// <typeparam name="T">The type of the data.</typeparam> /// <param name="data">The data to use.</param> /// <param name="serializer">The serializer to serialize /// the data.</param> /// <returns>A <see cref="BinaryData"/> instance.</returns> /// TODO - add cancellation token support /// once ObjectSerializer.SerializeAsync adds it. public static async Task <BinaryData> CreateAsync <T>( T data, ObjectSerializer serializer) => await CreateAsync <T>(data, serializer, true).ConfigureAwait(false);
/// <summary> /// Creates a BinaryData instance from the specified data using /// the specified type. /// </summary> /// <typeparam name="T">The type of the data.</typeparam> /// <param name="data">The data to use.</param> /// <param name="serializer">The serializer to serialize /// the data.</param> /// <returns>A <see cref="BinaryData"/> instance.</returns> public static BinaryData Create <T>( T data, ObjectSerializer serializer) => CreateAsync <T>(data, serializer, false).EnsureCompleted();
/// <summary> /// Initializes a new instance of <see cref="JsonPatchDocument"/> /// </summary> /// <param name="serializer">The <see cref="ObjectSerializer"/> instance to use for value serialization.</param> public JsonPatchDocument(ObjectSerializer serializer) { Operations = new Collection <JsonPatchOperation>(); _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); }
/// <summary> /// Converts the BinaryData to the specified type. /// </summary> /// <typeparam name="T">The type that the data should be /// converted to.</typeparam> /// <param name="serializer">The serializer to use /// when deserializing the data.</param> ///<returns>The data cast to the specified type. If the cast cannot ///be performed, an <see cref="InvalidCastException"/> will be ///thrown.</returns> /// TODO - add cancellation token support /// once ObjectSerializer.DeserializeAsync adds it. public async ValueTask <T> AsAsync <T>( ObjectSerializer serializer) => await AsAsync <T>(serializer, true).ConfigureAwait(false);
/// <summary> /// Converts the BinaryData to the specified type. /// </summary> /// <typeparam name="T">The type that the data should be /// converted to.</typeparam> /// <param name="serializer">The serializer to use /// when deserializing the data.</param> ///<returns>The data converted to the specified type.</returns> public T As <T>(ObjectSerializer serializer) => AsAsync <T>(serializer, false).EnsureCompleted();