예제 #1
0
        public void Equals_Object()
        {
            var signature = new MethodSignature(typeof(int), new[] { typeof(double), typeof(string) }, 12);

            object otherSignatureAsObject = new MethodSignature(typeof(int), new[] { typeof(double), typeof(string) }, 12);

            Assert.That(signature.Equals(otherSignatureAsObject), Is.True);

            Assert.That(signature.Equals((object)null), Is.False);

            object completelyUnrelatedObject = new object();

            Assert.That(signature.Equals(completelyUnrelatedObject), Is.False);
        }
예제 #2
0
        public void Equals_True()
        {
            var signature1 = new MethodSignature(typeof(int), new[] { typeof(double), typeof(string) }, 12);
            var signature2 = new MethodSignature(typeof(int), new[] { typeof(double), typeof(string) }, 12);

            Assert.That(signature1.Equals(signature2), Is.True);
        }
        public void Equals_NullObject_ReturnsFalse()
        {
            var target = new MethodSignature(SOME_TYPE_NAME, SOME_METHOD_NAME + "a");

            var actual = target.Equals(null);

            Assert.IsFalse(actual);
        }
예제 #4
0
        public void Equals_TwoDifferentSignatures()
        {
            var ms1 = new MethodSignature(typeof(Type[]), typeof(object), typeof(string));
            var ms2 = new MethodSignature(typeof(Type[]), typeof(object));

            Assert.AreNotEqual(ms1, ms2);
            Assert.IsFalse(ms1.Equals(null));
        }
        public void Equals_IdenticalValues_ReturnsTrue()
        {
            var target1 = new MethodSignature(SOME_TYPE_NAME, SOME_METHOD_NAME);
            var target2 = new MethodSignature(SOME_TYPE_NAME, SOME_METHOD_NAME);

            var actual = target1.Equals(target2);

            Assert.IsTrue(actual);
        }
        public void Equals_DifferentTypeName_ReturnsFalse()
        {
            var target1 = new MethodSignature(SOME_TYPE_NAME, SOME_METHOD_NAME + "a");
            var target2 = new MethodSignature(SOME_TYPE_NAME, SOME_METHOD_NAME);

            var actual = target1.Equals(target2);

            Assert.IsFalse(actual);
        }
예제 #7
0
        public void Equals_False()
        {
            var signature = new MethodSignature(typeof(int), new[] { typeof(double), typeof(string) }, 12);

            Assert.That(signature.Equals(null), Is.False);

            var signatureWithDifferentMethodType = new MethodSignature(typeof(string), new[] { typeof(double), typeof(string) }, 12);

            Assert.That(signature.Equals(signatureWithDifferentMethodType), Is.False);

            var signatureWithDifferentIndexParameters = new MethodSignature(typeof(int), new[] { typeof(string), typeof(double) }, 12);

            Assert.That(signature.Equals(signatureWithDifferentIndexParameters), Is.False);

            var signatureWithDifferentGenericParameterCount = new MethodSignature(typeof(int), new[] { typeof(double), typeof(string) }, 7);

            Assert.That(signature.Equals(signatureWithDifferentGenericParameterCount), Is.False);
        }
예제 #8
0
        private static MethodSignature getMethodToBeInvoked(List <MethodSignature> methodList, bool isStatic, MethodSignature callingMethod)
        {
            if (!isStatic)
            {
                MethodSignature methodSignature = methodList[(new Random()).Next(methodList.Count)];
                int             counter         = 300;

                while (methodSignature.Equals(callingMethod) && counter > 0)
                {
                    methodSignature = methodList[(new Random()).Next(methodList.Count)];
                }

                if (counter > 0 && !methodSignature.Equals(callingMethod))
                {
                    return(methodSignature);
                }
                return(null);
            }
            else
            {
                List <MethodSignature> staticMethods = new List <MethodSignature>();
                foreach (MethodSignature method in methodList)
                {
                    if (method.Static && !method.Equals(callingMethod))
                    {
                        staticMethods.Add(method);
                    }
                }

                if (staticMethods.Count == 0)
                {
                    return(null);
                }

                return(staticMethods[(new Random()).Next(staticMethods.Count)]);
            }
        }
예제 #9
0
파일: EcmaType.cs 프로젝트: Maximys/runtime
        public override MethodDesc GetMethod(string name, MethodSignature signature, Instantiation substitution)
        {
            var metadataReader = this.MetadataReader;
            var stringComparer = metadataReader.StringComparer;

            foreach (var handle in _typeDefinition.GetMethods())
            {
                if (stringComparer.Equals(metadataReader.GetMethodDefinition(handle).Name, name))
                {
                    var method = (EcmaMethod)_module.GetObject(handle);
                    if (signature == null || signature.Equals(method.Signature.ApplySubstitution(substitution)))
                        return method;
                }
            }

            return null;
        }
예제 #10
0
        public override MethodDesc GetMethod(string name, MethodSignature signature)
        {
            var metadataReader = this.MetadataReader;

            foreach (var handle in _typeDefinition.Methods)
            {
                if (metadataReader.GetMethod(handle).Name.StringEquals(name, metadataReader))
                {
                    MethodDesc method = (MethodDesc)_metadataUnit.GetMethod(handle, this);
                    if (signature == null || signature.Equals(method.Signature))
                    {
                        return(method);
                    }
                }
            }

            return(null);
        }
예제 #11
0
파일: EcmaType.cs 프로젝트: rivy/corert
        public override MethodDesc GetMethod(string name, MethodSignature signature)
        {
            var metadataReader = this.MetadataReader;
            var stringComparer = metadataReader.StringComparer;

            foreach (var handle in _typeDefinition.GetMethods())
            {
                if (stringComparer.Equals(metadataReader.GetMethodDefinition(handle).Name, name))
                {
                    MethodDesc method = (MethodDesc)_module.GetObject(handle);
                    if (signature == null || signature.Equals(method.Signature))
                    {
                        return(method);
                    }
                }
            }

            return(null);
        }
예제 #12
0
            public bool Equals(ref CachedSignatureRecord rhs)
            {
                var result =
                    (
                        (Method == rhs.Method) ||
                        (Method.FullName == rhs.Method.FullName)
                    ) &&
                    Signature.Equals(rhs.Signature) &&
                    (IsConstructor == rhs.IsConstructor);

                if (!result)
                {
                    return(false);
                }
                else
                {
                    return(result);
                }
            }
예제 #13
0
        public void TestSignatureMatches()
        {
            MetadataType atomType    = _testModule.GetType("", "Atom");
            MetadataType aType       = _testModule.GetType("", "A`1");
            MetadataType aOfAtomType = aType.MakeInstantiatedType(new Instantiation(atomType));


            MetadataType           baseClassType            = _testModule.GetType("", "BaseClass`2");
            MethodDesc             baseClassMethod          = baseClassType.GetMethods().Single(m => string.Equals(m.Name, "Method"));
            MethodSignature        baseClassMethodSignature = baseClassMethod.Signature;
            MethodSignatureBuilder matchingSignatureBuilder = new MethodSignatureBuilder(baseClassMethodSignature);

            matchingSignatureBuilder[0] = aOfAtomType;
            matchingSignatureBuilder[1] = atomType;
            MethodSignature matchingSignature = matchingSignatureBuilder.ToSignature();

            MetadataType             derivedClassType    = _testModule.GetType("", "DerivedClass");
            IEnumerable <MethodDesc> derivedClassMethods = derivedClassType.GetMethods().Where(m => string.Equals(m.Name, "Method"));
            IEnumerable <bool>       matches             = derivedClassMethods.Select(m => matchingSignature.Equals(m.Signature));
            int matchCount = matches.Select(b => b ? 1 : 0).Sum();

            Assert.Equal(1, matchCount);
        }
예제 #14
0
        public void Equals_SameClass()
        {
            var ms1 = new MethodSignature(typeof(Type[]), typeof(object));

            Assert.IsTrue(ms1.Equals(ms1));
        }