/// <summary> /// Creates a namespace (each DocType, DocRev & it's children reside in a dedicated namespace) that is suitable for /// parsing then reversing to it's original string representations. The transformations to and from DocTypeName/DocRev /// & C# namespace is a lossless operation. The inverse of this method is TryParseDocTypeAndRev. Segments for the /// DocType's actual name are prefixed with "doc", for the DocRev: "rev". Example: /// docMyName200.rev1.rev0.rev56.HERE.ARE.SOME.ADDITIONAL.NS_PARTS /// </summary> /// <param name="DocTypeName"></param> /// <param name="DocRev"></param> /// <param name="AdditionalRootNames"></param> /// <returns>DotTypeName as the root name & DocRev as the second level name if nothing specified in AdditionalRootNames</returns> public static string CalcCSharpNamespace(string DocTypeName, string DocRev, params string[] AdditionalRootNames) { Validate(DocTypeName, DocRev, AdditionalRootNames); string[] DocTypeNameParts = DocTypeName.Split('.').Select(s => String.Format("{0}{1}", DOCTYPENAME_NS_PREFIX, s.ToUpper())).ToArray(); string[] RevParts = DocRev.Split('.').Select(s => String.Format("{0}{1}", DOCREV_NS_PREFIX, s)).ToArray(); string[] OtherParts = AdditionalRootNames == null ? new string[] { } : AdditionalRootNames.Where(s => !String.IsNullOrWhiteSpace(s)).Select(s => String.Format("{0}{1}", ADDITIONAL_NS_PREFIX, StringTransform.SafeIdentifier(s ?? "_"))).ToArray(); return(String.Join(".", DocTypeNameParts.Concat(RevParts).Concat(OtherParts))); }
/// <summary> /// Creates a namespace (each DocType, DocRev & it's children reside in a dedicated namespace) that is suitable for /// parsing then reversing to it's original string representations. The transformations to and from DocTypeName/DocRev /// & C# namespace is a lossless operation. The inverse of this method is TryParseDocTypeAndRev. Segments for the /// DocType's actual name are prefixed with "doc", for the DocRev: "rev". Example: /// docFORM200.rev1.rev0.rev56.HERE.ARE.SOME.ADDITIONAL.NS_PARTS /// </summary> /// <param name="DocTypeName"></param> /// <param name="DocRev"></param> /// <param name="AdditionalRootNames"></param> /// <returns>DotTypeName as the root name & DocRev as the second level name if nothing specified in AdditionalRootNames</returns> internal static string CalcCSharpFullname(string DocTypeName, string DocRev, params string[] AdditionalRootNames) { // validate arguments if (INVALID_CSHARP_NAMESPACE_PART_MATCH.IsMatch(DocTypeName) | String.IsNullOrWhiteSpace(DocTypeName)) { throw new ArgumentException(String.Format("\"{0}\" is not a valid DocTypeName for namespace code generation operations"), DocTypeName); } if (INVALID_CSHARP_NAMESPACE_PART_MATCH.IsMatch(DocRev) | String.IsNullOrWhiteSpace(DocRev)) { throw new ArgumentException(String.Format("\"{0}\" is not a valid DocRev for namespace code generation operations"), DocRev); } if (AdditionalRootNames != null) { foreach (string test in AdditionalRootNames) { if (!String.IsNullOrWhiteSpace(test)) { if (INVALID_CSHARP_NAMESPACE_PART_MATCH.IsMatch(test)) { throw new ArgumentException(String.Format("\"{0}\" is not valid for namespace code generation operations"), test); } } } } string[] DocTypeNameParts = DocTypeName.Split('.').Select(s => String.Format("{0}{1}", DOCTYPENAME_NS_PREFIX, s.ToUpper())).ToArray(); string[] RevParts = DocRev.Split('.').Select(s => String.Format("{0}{1}", DOCREV_NS_PREFIX, s.ToUpper())).ToArray(); string[] OtherParts = AdditionalRootNames == null ? new string[] {} : AdditionalRootNames.Where(s => !String.IsNullOrWhiteSpace(s)).Select(s => String.Format("{0}{1}", ADDITIONAL_NS_PREFIX, StringTransform.SafeIdentifier(s ?? "_").ToUpper())).ToArray(); return(String.Join(".", DocTypeNameParts.Concat(RevParts).Concat(OtherParts))); }