/// <summary> /// Create resolver for this instruction /// </summary> public static ITextBindingResolver Create(string parameterWithBindings, IBindingResolverFactory resolverFactory) { // Parse bindings var matches = Regex.Matches(parameterWithBindings, BindingRegex); // No bindings, no resolver if (matches.Count == 0) { return(new NullResolver(parameterWithBindings)); } // Otherwise use the awesome regex resolver return(BuildRegexResolver(matches, parameterWithBindings, resolverFactory)); }
/// <summary> /// Build a regex resolver /// </summary> private static RegexResolver BuildRegexResolver(MatchCollection matches, string input, IBindingResolverFactory resolverFactory) { var propertyResolvers = new Dictionary <string, IBindingResolver>(); for (int index = 0; index < matches.Count; index++) { var match = matches[index]; var binding = match.Groups["binding"].Value; var resolver = (IBindingResolverChain)resolverFactory.Create(binding); if (resolver == null) // Could not be resolved, just keep for later { continue; } if (match.Groups["hasFormat"].Success) { // Add additional formatter to the end of the chain var format = match.Groups["format"].Value; resolver.Append(new FormatBindingResolver(format)); } propertyResolvers[match.Value] = resolver; } return(new RegexResolver(input, propertyResolvers)); }