clone - ShallowCopy with MemoryStream class c# -


i have generic methos deep copy. worried if may cause issues? 100% safe? if not, when can fail , should watch out for?

/// <summary> /// makes copy object. /// doesn't copy reference memory, data. /// </summary> /// <typeparam name="t">type of return object.</typeparam> /// <param name="item">object copied.</param> /// <returns>returns copied object.</returns> public static t clone<t>(this object item) {     if (item != null)     {         binaryformatter formatter = new binaryformatter();         memorystream stream = new memorystream();          formatter.serialize(stream, item);         stream.seek(0, seekorigin.begin);          t result = (t)formatter.deserialize(stream);          stream.close();          return result;     }     else         return default(t); } 

example:

customer customercopy = customer.clone<customer>(); 


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -