コード例 #1
0
        /// <summary>
        /// Lookups the specified method mapping.
        /// </summary>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="argumentTypes">The argument types.</param>
        /// <param name="genericArgumentTypes">The generic argument types.</param>
        /// <returns>The MethodMapping</returns>
        private IMethodMapping Lookup(string methodName, Type[] argumentTypes, params Type[] genericArgumentTypes)
        {
            Contract.Requires(!String.IsNullOrEmpty(methodName), "name is null or empty.");
            Contract.Requires(argumentTypes != null, "argTypes is null.");

            genericArgumentTypes = genericArgumentTypes ?? Type.EmptyTypes;

            return(this.mappings.FirstOrDefault(mapping =>
            {
                bool matches = mapping.Name == methodName;
                if (matches)
                {
                    matches =
                        comparer.GetHashCode(argumentTypes) == comparer.GetHashCode(mapping.ArgumentTypes.ToArray()) ||
                        comparer.Equals(argumentTypes, mapping.ArgumentTypes.ToArray());
                    if (matches)
                    {
                        matches =
                            comparer.GetHashCode(genericArgumentTypes) == comparer.GetHashCode(mapping.GenericArgumentTypes.ToArray()) ||
                            comparer.Equals(argumentTypes, mapping.GenericArgumentTypes.ToArray());
                    }
                }

                return matches;
            }));
        }
コード例 #2
0
        public void EqualsTest()
        {
            TypeArrayComparer target = new TypeArrayComparer();

            Type[] x    = new Type[] { typeof(string), typeof(Buffer), typeof(WeakReference) };
            Type[] xRef = x;
            Type[] y    = new Type[] { typeof(string), typeof(Buffer), typeof(WeakReference) };
            Type[] z    = new Type[] { typeof(OperatingSystem), typeof(Buffer), typeof(WeakReference) };

            Assert.IsTrue(target.Equals(x, xRef), "reference of a Type[] should be equal to another reference to the same Type[]");
            Assert.IsTrue(target.Equals(x, y), "Two arrays with the same elements, should be equal.");
            Assert.IsFalse(target.Equals(y, z), "Two arrays with different elements should be different.");
            Assert.IsFalse(target.Equals(x, z), "Two arrays with different elements should be different.");
        }
コード例 #3
0
        public void Equals_SameTypeSameSequence_ReturnsTrue()
        {
            var comparer = new TypeArrayComparer();
            Type[] firstArray = new[] { typeof(string), typeof(int) };
            Type[] secondArray = new[] { typeof(string), typeof(int) };

            Assert.True(comparer.Equals(firstArray, secondArray));
        }
コード例 #4
0
        public void Equals_UnidenticalArrays_ReturnsFalse()
        {
            var comparer = new TypeArrayComparer();
            Type[] firstArray = new[] { typeof(string) };
            Type[] secondArray = new[] { typeof(int) };

            Assert.False(comparer.Equals(firstArray, secondArray));
        }
コード例 #5
0
        public void Equals_SameTypeSameSequence_ReturnsTrue()
        {
            var comparer = new TypeArrayComparer();

            Type[] firstArray  = new[] { typeof(string), typeof(int) };
            Type[] secondArray = new[] { typeof(string), typeof(int) };

            Assert.IsTrue(comparer.Equals(firstArray, secondArray));
        }
コード例 #6
0
        public void Equals_UnidenticalArrays_ReturnsFalse()
        {
            var comparer = new TypeArrayComparer();

            Type[] firstArray  = new[] { typeof(string) };
            Type[] secondArray = new[] { typeof(int) };

            Assert.IsFalse(comparer.Equals(firstArray, secondArray));
        }