Exemple #1
0
 private IEnumerable <string> GetSubAliasNames(RegexAlias alias)
 {
     return(Regex.Matches(alias.RegexPattern, AliasPattern)
            .Cast <Match>()
            .Select(x => x.Value.Substring(2, x.Value.Length - 3))
            .Distinct());
 }
Exemple #2
0
        private void ComputeRawRegex(RegexAlias alias, List <RegexAlias> computedAliases)
        {
            // Add this as a computed dependency to detect circular dependencies
            computedAliases.Add(alias);

            foreach (var subAliasName in GetSubAliasNames(alias))
            {
                var matchName = string.Concat("%{", subAliasName, "}");

                // Find an alias with the specified name and put its
                //   regex pattern into the current alias' pattern
                var subAlias = _aliases.FirstOrDefault(x => x.Name.Equals(subAliasName, StringComparison.InvariantCultureIgnoreCase));
                if (subAlias != null)
                {
                    // If the subAlias has already been computed this run,
                    //   we have a circular dependency
                    if (computedAliases.Contains(subAlias))
                    {
                        throw new InvalidOperationException("Circular dependency detected while computing alias dependencies");
                    }

                    // Compute the sub alias' regex
                    ComputeRawRegex(subAlias, computedAliases.ToList());
                    alias.RegexPattern = alias.RegexPattern.Replace(matchName, subAlias.RegexPattern);
                }
            }
        }