示例#1
0
        /// <summary>
        /// Test values for equality accross type boundaries except string to non-char, null-safe
        /// </summary>
        /// <param name="value">The first value.</param>
        /// <param name="otherValue">The second value.</param>
        /// <returns>True if the values are equal, false otherwise.</returns>
        public static bool BackCompatSafeTypeInsensitiveEqual(this object value, object otherValue)
        {
            // NOTE(daviburg): Historically testing for equality cross integer and string boundaries resulted in not equal.
            // This ensures we preserve the behavior.
            if (value is string && !(otherValue is char) || otherValue is string && !(value is char))
            {
                return(false);
            }

            return(ObjectExtensionMethods.SafeTypeInsensitiveEqual(value: value, otherValue: otherValue));
        }
示例#2
0
        /// <summary>
        /// Test values for equality accross type boundaries except string to non-char, null-safe
        /// </summary>
        /// <param name="value">The first value.</param>
        /// <param name="otherValue">The second value.</param>
        /// <returns>True if the values are equal, false otherwise.</returns>
        public static bool BackCompatSafeTypeInsensitiveEqual(this object value, object otherValue)
        {
            if (value != null && otherValue != null)
            {
                // NOTE(daviburg): Historically testing for equality cross integer and string boundaries resulted in not equal.
                // This ensures we preserve the behavior.
                var comparedTypes = new HashSet <Type>()
                {
                    value.GetType(), otherValue.GetType()
                };
                if (comparedTypes.Count > 1 && _BackCompatComparableTypeBoundaries.All(boundary => !comparedTypes.IsSubsetOf(boundary)))
                {
                    return(false);
                }
            }

            return(ObjectExtensionMethods.SafeTypeInsensitiveEqual(value: value, otherValue: otherValue));
        }