예제 #1
0
 private MethodInfo FindMethod(Type typeToCreate)
 {
     ParameterMatcher matcher = new ParameterMatcher(methodParameters);
     foreach(MethodInfo method in typeToCreate.GetMethods())
     {
         if(MethodNameMatches(method, methodName))
         {
             if(matcher.Matches(method.GetParameters()))
             {
                 return method;
             }
         }
     }
     return null;
 }
        private ConstructorInfo FindConstructor(Type typeToCreate)
        {
            var matcher = new ParameterMatcher(parameterValues);
            foreach(ConstructorInfo ctor in typeToCreate.GetConstructors())
            {
                if(matcher.Matches(ctor.GetParameters()))
                {
                    return ctor;
                }
            }

            string signature = string.Join(", ", parameterValues.Select(p => p.ParameterTypeName).ToArray());

            throw new InvalidOperationException(
                string.Format(CultureInfo.CurrentCulture,
                    Resources.NoSuchConstructor,
                    typeToCreate.FullName,
                    signature));
        }
예제 #3
0
 public void SameLengthSameTypesMatch()
 {
     ParameterMatcher matcher = new ParameterMatcher(Parameters(typeof(int), typeof(string)));
     Assert.IsTrue(matcher.Matches(Types(typeof(int), typeof(string))));
 }
예제 #4
0
 public void SameLengthDifferentTypesDontMatch()
 {
     ParameterMatcher matcher = new ParameterMatcher(Parameters(typeof(int)));
     Assert.IsFalse(matcher.Matches(Types(typeof(string))));
 }
예제 #5
0
 public void OpenGenericTypesMatch()
 {
     ParameterMatcher matcher = new ParameterMatcher(Parameters(typeof(ICommand<>), typeof(ICommand<>)));
     Assert.IsTrue(matcher.Matches(Types(typeof(ICommand<>), typeof(ICommand<>))));
 }
예제 #6
0
 public void MismatchedParameterListsDontMatch()
 {
     ParameterMatcher matcher = new ParameterMatcher(Parameters());
     Assert.IsFalse(matcher.Matches(Types(typeof(int))));
 }
예제 #7
0
        public void EmptyParameterListMatches()
        {
            ParameterMatcher matcher = new ParameterMatcher(Parameters());

            Assert.IsTrue(matcher.Matches(Types()));
        }