Пример #1
0
        private ConstructorInfo FindConstructor(Type typeToCreate)
        {
            var matcher = new ParameterMatcher(this.parameterValues);
            var typeToCreateReflector = new ReflectionHelper(typeToCreate);

            foreach (ConstructorInfo ctor in typeToCreateReflector.InstanceConstructors)
            {
                if (matcher.Matches(ctor.GetParameters()))
                {
                    return ctor;
                }
            }

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

            throw new InvalidOperationException(
                string.Format(CultureInfo.CurrentCulture,
                    Resources.NoSuchConstructor,
                    typeToCreate.FullName,
                    signature));
        }
Пример #2
0
 private MethodInfo FindMethod(Type typeToCreate)
 {
     ParameterMatcher matcher = new ParameterMatcher(this.methodParameters);
     foreach (MethodInfo method in typeToCreate.GetMethodsHierarchical())
     {
         if (this.MethodNameMatches(method, this.methodName))
         {
             if (matcher.Matches(method.GetParameters()))
             {
                 return method;
             }
         }
     }
     return null;
 }
Пример #3
0
 public void SameLengthSameTypesMatch()
 {
     ParameterMatcher matcher = new ParameterMatcher(Parameters(typeof(int), typeof(string)));
     Assert.True(matcher.Matches(Types(typeof(int), typeof(string))));
 }
Пример #4
0
 public void SameLengthDifferentTypesDontMatch()
 {
     ParameterMatcher matcher = new ParameterMatcher(Parameters(typeof(int)));
     Assert.False(matcher.Matches(Types(typeof(string))));
 }
Пример #5
0
 public void OpenGenericTypesMatch()
 {
     ParameterMatcher matcher = new ParameterMatcher(Parameters(typeof(ICommand<>), typeof(ICommand<>)));
     Assert.True(matcher.Matches(Types(typeof(ICommand<>), typeof(ICommand<>))));
 }
Пример #6
0
 public void MismatchedParameterListsDontMatch()
 {
     ParameterMatcher matcher = new ParameterMatcher(Parameters());
     Assert.False(matcher.Matches(Types(typeof(int))));
 }
Пример #7
0
        public void EmptyParameterListMatches()
        {
            ParameterMatcher matcher = new ParameterMatcher(Parameters());

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