/// <summary> /// Deserializes a <see cref="Stream"/> to the specified <paramref name="instance"/>. /// </summary> /// <typeparam name="TFormatter">The <see cref="Type"/> used to deserialize the <paramref name="instance"/>.</typeparam> /// <param name="instance">The instance that the <paramref name="stream"/> will be deserialized to.</param> /// <param name="stream">The <see cref="Stream"/> containing the data to deserialize.</param> /// <exception cref="ArgumentNullException"> thrown if the <paramref name="instance"/> or <paramref name="stream"/> is <c>Null</c>.</exception> /// <exception cref="ArgumentException"> thrown if the <typeparamref name="TFormatter"/> is not a valid Serialization formatter <see cref="Type"/>.</exception> public static void Deserialize <TFormatter>(this ISerializable instance, Stream stream) where TFormatter : class, new() { if (instance.IsNull()) { throw new ArgumentNullException("instance"); } if (stream.IsNull()) { throw new ArgumentNullException("stream"); } if (!SerializationExtensions.IsSerializableFormatter <TFormatter>()) { throw new InvalidOperationException("The specified Type is not a valid Serialization Formatter."); } TFormatter formatter = new TFormatter(); formatter.ExecuteMethod(SerializationMethods.Deserialize, stream).CopyTo(instance); }