Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        ///// <summary>
        ///// Static method to write an object to a stream
        ///// </summary>
        ///// <typeparam name="T">Type of the object to be written</typeparam>
        ///// <param name="myObject">Object to be written</param>
        ///// <param name="stream">Stream to which to write the object</param>
        //public static void WriteToXMLStream<T>(this T myObject, Stream stream)
        //{
        //    var dcs = new DataContractSerializer(typeof(T), KnownTypes.CurrentKnownTypes.Values);
        //    dcs.WriteObject(stream, myObject);
        //}

        /// <summary>
        /// Static method to write an object to a stream
        /// </summary>
        /// <typeparam name="T">Type of the object to be written</typeparam>
        /// <param name="myObject">Object to be written</param>
        /// <param name="stream">Stream to which to write the object</param>
        public static void WriteJsonToStream <T>(this T myObject, Stream stream)
        {
            var serializedJson = VtsJsonSerializer.WriteToJson(myObject);

            WriteTextToStream(serializedJson, stream);
        }