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

php - Passing multiple values in a url using checkbox -

compilation - PHP install fails on Ubuntu 14 (make: *** [sapi/cli/php] Error 1) PHP 5.6.20 -

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