public static GetNameCaptureGroup ( string groupName ) : string | ||
groupName | string | Name of capture group to create |
return | string |
/// <summary> /// Adds a standard type mapping based on namespace RegEx replace and filter patterns /// </summary> /// <param name="nsSourceReplaceRegEx">RegEx replace pattern for source namespace</param> /// <param name="nsSourceFilterRegEx">RegEx filter pattern for source namespace</param> /// <param name="nsTargetsRegEx">Array of RegEx replace values for target namespaces</param> /// <param name="viewSuffix">Suffix for type name. Should be "View" or synonym of "View". (Optional)</param> public static void AddTypeMapping(string nsSourceReplaceRegEx, string nsSourceFilterRegEx, string[] nsTargetsRegEx, string viewSuffix = "View") { RegisterViewSuffix(viewSuffix); var replist = new List <string>(); var repsuffix = useNameSuffixesInMappings ? viewSuffix : String.Empty; const string basegrp = "${basename}"; foreach (var t in nsTargetsRegEx) { replist.Add(t + String.Format(nameFormat, basegrp, repsuffix)); } string rxbase = RegExHelper.GetNameCaptureGroup("basename"); string suffix = String.Empty; if (useNameSuffixesInMappings) { suffix = viewModelSuffix; if (!viewModelSuffix.Contains(viewSuffix) && includeViewSuffixInVmNames) { suffix = viewSuffix + suffix; } } var rxsrcfilter = String.IsNullOrEmpty(nsSourceFilterRegEx) ? null : String.Concat(nsSourceFilterRegEx, String.Format(nameFormat, RegExHelper.NameRegEx, suffix), "$"); var rxsuffix = RegExHelper.GetCaptureGroup("suffix", suffix); NameTransformer.AddRule( String.Concat(nsSourceReplaceRegEx, String.Format(nameFormat, rxbase, rxsuffix), "$"), replist.ToArray(), rxsrcfilter ); }
/// <summary> /// Adds a standard type mapping based on namespace RegEx replace and filter patterns /// </summary> /// <param name="nsSourceReplaceRegEx">RegEx replace pattern for source namespace</param> /// <param name="nsSourceFilterRegEx">RegEx filter pattern for source namespace</param> /// <param name="nsTargetsRegEx">Array of RegEx replace values for target namespaces</param> /// <param name="viewSuffix">Suffix for type name. Should be "View" or synonym of "View". (Optional)</param> public static void AddTypeMapping(string nsSourceReplaceRegEx, string nsSourceFilterRegEx, string[] nsTargetsRegEx, string viewSuffix = "View") { var replist = new List <string>(); Action <string> func; const string basegrp = "${basename}"; var interfacegrp = "${" + InterfaceCaptureGroupName + "}"; if (useNameSuffixesInMappings) { if (viewModelSuffix.Contains(viewSuffix) || !includeViewSuffixInVmNames) { var nameregex = String.Format(nameFormat, basegrp, viewModelSuffix); func = t => { replist.Add(t + "I" + nameregex + interfacegrp); replist.Add(t + "I" + basegrp + interfacegrp); replist.Add(t + nameregex); replist.Add(t + basegrp); }; } else { var nameregex = String.Format(nameFormat, basegrp, "${suffix}" + viewModelSuffix); func = t => { replist.Add(t + "I" + nameregex + interfacegrp); replist.Add(t + nameregex); }; } } else { func = t => { replist.Add(t + "I" + basegrp + interfacegrp); replist.Add(t + basegrp); }; } nsTargetsRegEx.ToList().ForEach(t => func(t)); string suffix = useNameSuffixesInMappings ? viewSuffix : String.Empty; var srcfilterregx = String.IsNullOrEmpty(nsSourceFilterRegEx) ? null : String.Concat(nsSourceFilterRegEx, String.Format(nameFormat, RegExHelper.NameRegEx, suffix), "$"); var rxbase = RegExHelper.GetNameCaptureGroup("basename"); var rxsuffix = RegExHelper.GetCaptureGroup("suffix", suffix); //Add a dummy capture group -- place after the "$" so it can never capture anything var rxinterface = RegExHelper.GetCaptureGroup(InterfaceCaptureGroupName, String.Empty); NameTransformer.AddRule( String.Concat(nsSourceReplaceRegEx, String.Format(nameFormat, rxbase, rxsuffix), "$", rxinterface), replist.ToArray(), srcfilterregx ); }