NullSafeEquals() public static method

Determine if the given objects are equal, returning if both are respectively if only one is .
public static NullSafeEquals ( object o1, object o2 ) : bool
o1 object The first object to compare.
o2 object The second object to compare.
return bool
コード例 #1
0
        public void NullSafeEqualsNotEqual()
        {
            string first  = "this is it";
            int    second = 12;

            Assert.IsFalse(ObjectUtils.NullSafeEquals(first, second));
        }
コード例 #2
0
        public void NullSafeEqualsBothEquals()
        {
            string first  = "this is it";
            string second = "this is it";

            Assert.IsTrue(ObjectUtils.NullSafeEquals(first, second));
        }
コード例 #3
0
        public void NullSafeEqualsWithBothNull()
        {
            string first  = null;
            string second = null;

            Assert.IsTrue(ObjectUtils.NullSafeEquals(first, second));
        }
コード例 #4
0
        public void NullSafeEqualsWithSecondNull()
        {
            string first  = "";
            string second = null;

            Assert.IsFalse(ObjectUtils.NullSafeEquals(first, second));
        }
コード例 #5
0
 /// <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);
 }