///// <summary> ///// Static method to read a specified type from a stream ///// </summary> ///// <typeparam name="T">Type of the data to be read</typeparam> ///// <param name="stream">Stream from which to read</param> ///// <returns>The data as the specified type</returns> //public static T ReadFromStream<T>(Stream stream) //{ // var dcs = new DataContractSerializer(typeof(T), KnownTypes.CurrentKnownTypes.Values); // return (T)dcs.ReadObject(stream); //} /// <summary> /// Static method to read a specified type from a stream /// </summary> /// <typeparam name="T">Type of the data to be read</typeparam> /// <param name="stream">Stream from which to read</param> /// <returns>The data as the specified type</returns> public static T ReadFromJsonStream <T>(Stream stream) { using (var sr = new StreamReader(stream)) { var serializedJson = sr.ReadToEnd(); var myObject = VtsJsonSerializer.ReadFromJson <T>(serializedJson); return(myObject); } }
/// <summary> /// Static method to clone an object /// </summary> /// <typeparam name="T">Type of the object</typeparam> /// <param name="myObject">The object to clone</param> /// <returns>A clone of the object</returns> public static T Clone <T>(this T myObject) { var serialized = VtsJsonSerializer.WriteToJson(myObject); return(VtsJsonSerializer.ReadFromJson <T>(serialized)); }