Exemplo n.º 1
0
        public string Build(IDictionary <string, object> routeValues, IDictionary <string, string> overrideValues = null)
        {
            _composer.Initialize(_url.Length);

            int position = 0;

            foreach (Match match in ParameterMatcher.Matches(_url))
            {
                _composer.AppendText(_url.Substring(position, match.Index - position));

                string parameterName  = match.Groups[ParameterName].Value;
                string parameterValue = GetParameterValue(parameterName, routeValues, overrideValues);
                if (parameterValue == null)
                {
                    _composer.AppendParameterName(parameterName);
                }
                else
                {
                    _composer.AppendParameterValue(parameterValue);
                }
                position = match.Index + match.Length;
            }
            if (position < _url.Length)
            {
                _composer.AppendText(_url.Substring(position));
            }
            return(_composer.ToString());
        }
        private ConstructorInfo FindExactMatchingConstructor(Type typeToCreate)
        {
            var matcher = new ParameterMatcher(_parameterValues);
            var typeToCreateReflector = new ReflectionHelper(typeToCreate);

            foreach (ConstructorInfo ctor in typeToCreateReflector.InstanceConstructors)
            {
                if (matcher.Matches(ctor.GetParameters()))
                {
                    return(ctor);
                }
            }
            return(null);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        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));
        }
        private ConstructorInfo FindConstructor(Type typeToCreate)
        {
            ParameterMatcher matcher = new ParameterMatcher(parameterValues);

            foreach (ConstructorInfo ctor in typeToCreate.GetConstructors())
            {
                if (matcher.Matches(ctor.GetParameters()))
                {
                    return(ctor);
                }
            }

            string signature = Sequence.ToString(parameterValues,
                                                 ", ",
                                                 delegate(InjectionParameterValue parameter) { return(parameter.ParameterTypeName); });

            throw new InvalidOperationException(
                      string.Format(CultureInfo.CurrentCulture,
                                    Resources.NoSuchConstructor,
                                    typeToCreate.FullName,
                                    signature));
        }
Exemplo n.º 6
0
        public void OpenGenericTypesMatch()
        {
            ParameterMatcher matcher = new ParameterMatcher(Parameters(typeof(ICommand <>), typeof(ICommand <>)));

            Assert.IsTrue(matcher.Matches(Types(typeof(ICommand <>), typeof(ICommand <>))));
        }
Exemplo n.º 7
0
        public void SameLengthSameTypesMatch()
        {
            ParameterMatcher matcher = new ParameterMatcher(Parameters(typeof(int), typeof(string)));

            Assert.IsTrue(matcher.Matches(Types(typeof(int), typeof(string))));
        }
Exemplo n.º 8
0
        public void SameLengthDifferentTypesDontMatch()
        {
            ParameterMatcher matcher = new ParameterMatcher(Parameters(typeof(int)));

            Assert.IsFalse(matcher.Matches(Types(typeof(string))));
        }
Exemplo n.º 9
0
        public void MismatchedParameterListsDontMatch()
        {
            ParameterMatcher matcher = new ParameterMatcher(Parameters());

            Assert.IsFalse(matcher.Matches(Types(typeof(int))));
        }
Exemplo n.º 10
0
        public void EmptyParameterListMatches()
        {
            ParameterMatcher matcher = new ParameterMatcher(Parameters());

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