コード例 #1
0
        public bool Test_IsIn_List_with_comparer(string commaDelimitedArray, string value)
        {
            var enumerable = commaDelimitedArray == null
                ? null
                : commaDelimitedArray.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            var caseInsensitiveComparer = EqualityComparerFunc <string> .Create((s1, s2) => string.Equals(s1, s2, StringComparison.OrdinalIgnoreCase));

            return(value.IsIn(enumerable, caseInsensitiveComparer));
        }
コード例 #2
0
        public bool Compare_Contains_Tests(int a, int b, int c, int d, int e, int search)
        {
            Func <int, int, bool> absoluteEqualityFunc = (x, y) =>
            {
                return(Math.Abs(x) == Math.Abs(y));
            };

            var list = new[] { a, b, c, d, e };

            var contains = list.Contains(search, EqualityComparerFunc <int> .Create(absoluteEqualityFunc));

            return(contains);
        }
コード例 #3
0
        public string Test_Append_CaseInsensitiveComparer(string commaDelimitedArray, string value)
        {
            var comparer = EqualityComparerFunc <string> .Create(
                (s1, s2) => string.Equals(s1, s2, StringComparison.OrdinalIgnoreCase)
                );

            var enumerable = commaDelimitedArray == null
                ? null
                : commaDelimitedArray.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            var result = enumerable.AppendItem(value, comparer);

            return(string.Join(",", result));
        }
コード例 #4
0
        public void GetHashCode_generates_constant_values(string valueList)
        {
            Func <int, int, bool> absoluteEqualityFunc = (x, y) =>
            {
                return(x == y);
            };

            var comparer = EqualityComparerFunc <int> .Create(absoluteEqualityFunc);

            var list = valueList.Split(",".ToCharArray())
                       .Select(x => Convert.ToInt32(x))
                       .ToList();

            var hashCodes = list
                            .Select(x => comparer.GetHashCode(x));

            hashCodes
            .All(hc => hc.Equals(0)).ShouldBeTrue();
        }
コード例 #5
0
        /// <summary>
        /// Appends the specified item instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumerable">The enumerable.</param>
        /// <param name="instance">The instance.</param>
        /// <returns>IEnumerable&lt;T&gt;.</returns>
        public static IEnumerable <T> AppendItem <T>(this IEnumerable <T> enumerable, T instance)
        {
            var falseComparer = EqualityComparerFunc <T> .Create((arg1, arg2) => false);

            return(enumerable.AppendItem(instance, falseComparer));
        }