public static NullSafeEquals ( object o1, object o2 ) : bool | ||
o1 | object | The first object to compare. |
o2 | object | The second object to compare. |
return | bool |
public void NullSafeEqualsNotEqual() { string first = "this is it"; int second = 12; Assert.IsFalse(ObjectUtils.NullSafeEquals(first, second)); }
public void NullSafeEqualsBothEquals() { string first = "this is it"; string second = "this is it"; Assert.IsTrue(ObjectUtils.NullSafeEquals(first, second)); }
public void NullSafeEqualsWithBothNull() { string first = null; string second = null; Assert.IsTrue(ObjectUtils.NullSafeEquals(first, second)); }
public void NullSafeEqualsWithSecondNull() { string first = ""; string second = null; Assert.IsFalse(ObjectUtils.NullSafeEquals(first, second)); }
/// <summary> Match a String against the given pattern, supporting the following simple /// pattern styles: "xxx*", "*xxx" and "*xxx*" matches, as well as direct equality. /// </summary> /// <param name="pattern">the pattern to match against /// </param> /// <param name="str">the String to match /// </param> /// <returns> whether the String matches the given pattern /// </returns> public static bool SimpleMatch(System.String pattern, System.String str) { if (ObjectUtils.NullSafeEquals(pattern, str) || "*".Equals(pattern)) { return(true); } if (pattern == null || str == null) { return(false); } if (pattern.StartsWith("*") && pattern.EndsWith("*") && str.IndexOf(pattern.Substring(1, (pattern.Length - 1) - (1))) != -1) { return(true); } if (pattern.StartsWith("*") && str.EndsWith(pattern.Substring(1, (pattern.Length) - (1)))) { return(true); } if (pattern.EndsWith("*") && str.StartsWith(pattern.Substring(0, (pattern.Length - 1) - (0)))) { return(true); } return(false); }