Created
September 14, 2012 18:39
-
-
Save kcargile/3723840 to your computer and use it in GitHub Desktop.
.NET Determines if the two objects are equivalent in a way that will not throw if either is 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> | |
/// Determines if the two objects are equivalent in a way that will not throw if either is null. | |
/// </summary> | |
/// <param name="param">The param.</param> | |
/// <param name="obj">The obj.</param> | |
/// <returns><c>true</c> if the two objects are equivalent; otherwise, <c>false</c>.</returns> | |
public static bool NullSafeEquals(this object param, object obj) | |
{ | |
return null != param ? param.Equals(obj) : (null == obj ? true : false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment