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); }
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); }
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)); }
public void OpenGenericTypesMatch() { ParameterMatcher matcher = new ParameterMatcher(Parameters(typeof(ICommand <>), typeof(ICommand <>))); Assert.IsTrue(matcher.Matches(Types(typeof(ICommand <>), typeof(ICommand <>)))); }
public void SameLengthSameTypesMatch() { ParameterMatcher matcher = new ParameterMatcher(Parameters(typeof(int), typeof(string))); Assert.IsTrue(matcher.Matches(Types(typeof(int), typeof(string)))); }
public void SameLengthDifferentTypesDontMatch() { ParameterMatcher matcher = new ParameterMatcher(Parameters(typeof(int))); Assert.IsFalse(matcher.Matches(Types(typeof(string)))); }
public void MismatchedParameterListsDontMatch() { ParameterMatcher matcher = new ParameterMatcher(Parameters()); Assert.IsFalse(matcher.Matches(Types(typeof(int)))); }
public void EmptyParameterListMatches() { ParameterMatcher matcher = new ParameterMatcher(Parameters()); Assert.IsTrue(matcher.Matches(Types())); }