static string BuildNamePattern(MemberInfo member, CommandAttribute commandAttr) { // find module prefixes var prefixes = new List <string>(); var type = member.DeclaringType; do { var moduleAttr = type.GetCustomAttribute <ModuleAttribute>(); // add if prefixed if (moduleAttr != null && moduleAttr.IsPrefixed) { prefixes.Add(string.Join('|', moduleAttr.GetNames())); } // traverse upwards type = type.DeclaringType; }while (type != null); // reverse prefixes.Reverse(); var builder = new StringBuilder().Append('^'); // prepend prefixes foreach (var prefix in prefixes) { builder .Append('(') .Append(prefix) .Append(')') .Append(@"\b\s+"); } if (commandAttr.BindName) { builder .Append('(') .Append(string.Join('|', commandAttr.GetNames())) .Append(')') .Append(@"($|\s+)"); } return(builder.ToString()); }