/// <summary> /// Adds a standard type mapping by substituting one subnamespace for another /// </summary> /// <param name="nsSource">Subnamespace of source type</param> /// <param name="nsTargets">Subnamespaces of target type as an array</param> /// <param name="viewSuffix">Suffix for type name. Should be "View" or synonym of "View". (Optional)</param> public static void AddSubNamespaceMapping(string nsSource, string[] nsTargets, string viewSuffix = DefaultViewSuffix) { //need to terminate with "." in order to concatenate with type name later var nsencoded = RegExHelper.NamespaceToRegEx(nsSource + "."); string rxbeforetgt, rxaftersrc, rxaftertgt; string rxbeforesrc = rxbeforetgt = rxaftersrc = rxaftertgt = String.Empty; if (!String.IsNullOrEmpty(nsSource)) { if (!nsSource.StartsWith("*")) { rxbeforesrc = RegExHelper.GetNamespaceCaptureGroup("nsbefore"); rxbeforetgt = @"${nsbefore}"; } if (!nsSource.EndsWith("*")) { rxaftersrc = RegExHelper.GetNamespaceCaptureGroup("nsafter"); rxaftertgt = "${nsafter}"; } } var rxmid = RegExHelper.GetCaptureGroup("subns", nsencoded); var nsreplace = String.Concat(rxbeforesrc, rxmid, rxaftersrc); var nsTargetsRegEx = nsTargets.Select(t => String.Concat(rxbeforetgt, t, ".", rxaftertgt)).ToArray(); AddTypeMapping(nsreplace, null, nsTargetsRegEx, viewSuffix); }
public void GetNameCaptureGroupShouldUseNameSpaceRegEx() { var groupName = "group"; var result = RegExHelper.GetNamespaceCaptureGroup(groupName); Assert.Equal(@"(?<group>([\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}_][\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\p{Cf}_]*\.)*)", result); }
public void GetNameCaptureGroupShouldUseNameSpaceRegEx() { var groupName = "group"; var result = RegExHelper.GetNamespaceCaptureGroup(groupName); Assert.Equal(@"(?<group>([A-Za-z_]\w*\.)*)", result); }
private static void AddCustomNamingConventions() { const string groupName = "subname"; string captureGroup = RegExHelper.GetNamespaceCaptureGroup("subname"); string viewPattern = captureGroup + @"View"; const string viewReplacement = @"${" + groupName + "}ViewModel"; ViewModelLocator.NameTransformer.AddRule(viewPattern, viewReplacement); string viewModelPattern = captureGroup + @"ViewModel"; const string viewModelReplacement = @"${" + groupName + "}View"; ViewLocator.NameTransformer.AddRule(viewModelPattern, viewModelReplacement); }