Created
September 14, 2012 19:29
-
-
Save kcargile/3724170 to your computer and use it in GitHub Desktop.
.NET Clones the current instance in a way that is safe even it if it null.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Extensions | |
{ | |
/// <summary> | |
/// Contains <see cref="object"/> extension methods. | |
/// </summary> | |
public static class ObjectExtensions | |
{ | |
/// <summary> | |
/// Clones the current instance in a way that is safe even it if it null. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <param name="param">The param.</param> | |
/// <returns>A deep copy of <b>param</b> or null.</returns> | |
public static T NullSafeClone<T>(this T param) where T : class, ICloneable | |
{ | |
return null != param ? (T)param.Clone() : null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment