/// <summary> /// Returns a node definition with just the type name's header. /// This is specific to graph-viz (ver. 2.38+) /// </summary> /// <param name="typeFullName"></param> /// <param name="enumValues">Optional values to be listed as line items with no type specifiers nor .gv port ids.</param> /// <returns></returns> public static string EmptyGraphVizClassNode(string typeFullName, string[] enumValues) { var className = NfReflect.GetTypeNameWithoutNamespace(typeFullName); var ns = NfReflect.GetNamespaceWithoutTypeName(typeFullName); var fullName = string.Format("{0}{1}", string.IsNullOrWhiteSpace(ns) ? string.Empty : ns + ".", className); var graphViz = new StringBuilder(); graphViz.Append(NfString.SafeDotNetIdentifier(fullName)); graphViz.AppendLine(" [shape=Mrecord, label=<<table bgcolor=\"white\" border=\"0\" >"); graphViz.AppendLine("<th>"); graphViz.AppendLine("<td bgcolor=\"grey\" align=\"center\">"); graphViz.Append("<font color=\"white\">"); graphViz.AppendFormat("{0} :: {1}", className, string.IsNullOrWhiteSpace(ns) ? "global" : ns); graphViz.AppendLine("</font></td></th>"); if (enumValues != null && enumValues.Length > 0) { foreach (var enumVal in enumValues) { graphViz.Append("<tr><td><font color=\"blue\">"); graphViz.Append(enumVal); graphViz.AppendLine("</font></td></tr>"); } } else { graphViz.AppendLine("<tr><td></td></tr>"); graphViz.AppendLine("<tr><td></td></tr>"); } graphViz.AppendLine("</table>> ];"); return(graphViz.ToString()); }
public NfTypeName(string name) { if (string.IsNullOrWhiteSpace(name)) { return; } _ctorString = name; var parseItem = TypeNameParseTree.ParseIl(name); if (parseItem == null) { return; } _className = NfReflect.GetTypeNameWithoutNamespace(parseItem.FullName); _namespace = NfReflect.GetNamespaceWithoutTypeName(parseItem.FullName); _publicKeyToken = parseItem.PublicKeyTokenValue; if (!string.IsNullOrWhiteSpace(parseItem.AssemblyFullName)) { _asmName = new AssemblyName(parseItem.AssemblyFullName); } if (parseItem.GenericItems == null || !parseItem.GenericItems.Any()) { return; } foreach (var gi in parseItem.GenericItems) { _genericArgs.Add(new NfTypeName(gi)); } }
public HbmCommand(string typeFullName, string idTypeFullName) { TypeFullName = typeFullName; IdTypeFullName = idTypeFullName; OuputNamespace = NfReflect.GetTypeNameWithoutNamespace(TypeFullName); IdTypeTest = Gen.Settings.LangStyle.GenUseIsNotDefaultValueTest(IdTypeFullName, "DataId"); ClassName = NfReflect.GetTypeNameWithoutNamespace(TypeFullName); }
public bool TryFindLastLineInClass(string typename, string[] srcFileLines, out int lastLine) { lastLine = int.MaxValue; if (srcFileLines == null) { return(false); } var srcFile = srcFileLines.ToArray(); if (String.IsNullOrWhiteSpace(typename)) { return(false); } if (srcFile.Length <= 0) { return(false); } lastLine = srcFile.Length; //these preserve all lines srcFile = RemoveLineComments(srcFile, LINE_COMMENT_CHAR_SEQ); srcFile = RemoveBlockComments(srcFile); var joinedContent = string.Join("\n", srcFile); var myXDocFrame = new XDocFrame(C_OPEN_CURLY, C_CLOSE_CURLY); var mytokens = myXDocFrame.FindEnclosingTokens(joinedContent); if (mytokens == null || mytokens.Count < 1) { return(false); } var targetToken = NfReflect.GetTypeNameWithoutNamespace(typename) == typename ? mytokens[0] : mytokens[1]; var joinedContentAsChars = joinedContent.ToCharArray(); //need to count the number of newlines from the bottom up to token's end for (var i = joinedContent.Length - 1; i >= targetToken.End; i--) { if (joinedContentAsChars[i] != '\n') { continue; } lastLine -= 1; } //add one more if (lastLine < srcFile.Length) { lastLine -= 1; } return(lastLine < srcFile.Length); }
public void TestGetTypeNameWithoutNamespace() { var testResult = NfReflect.GetTypeNameWithoutNamespace("NoFuture.Asm.Fii.MyType"); Console.WriteLine(testResult); Assert.AreEqual("MyType", testResult); testResult = NfReflect.GetTypeNameWithoutNamespace("My_SillyName_NoNamespace_Pos_Class"); Console.WriteLine(testResult); Assert.AreEqual("My_SillyName_NoNamespace_Pos_Class", testResult); testResult = NfReflect.GetNamespaceWithoutTypeName( "Wanker.DCF.UI.Controller.Operator.OperatorUIController::set_OperatorContacts(Wanker.DCF.DTO.WankerContact)"); }
public bool TryFindFirstLineInClass(string typename, string[] srcFileLines, out int firstLine) { firstLine = 1; if (srcFileLines == null) { return(false); } var srcFile = srcFileLines.ToArray(); if (String.IsNullOrWhiteSpace(typename)) { return(false); } if (srcFile.Length <= 0) { return(false); } //these preserve all lines srcFile = RemoveLineComments(srcFile, LINE_COMMENT_CHAR_SEQ); srcFile = RemoveBlockComments(srcFile); var joinedContent = String.Join("\n", srcFile); var myXDocFrame = new XDocFrame(C_OPEN_CURLY, C_CLOSE_CURLY); var mytokens = myXDocFrame.FindEnclosingTokens(joinedContent); if (mytokens == null || mytokens.Count < 1) { return(false); } var targetToken = NfReflect.GetTypeNameWithoutNamespace(typename) == typename ? mytokens[0] : mytokens[1]; var joinedContentAsChars = joinedContent.ToCharArray(); //need to count the number of newlines up to the token's start for (var i = 0; i <= targetToken.Start; i++) { if (joinedContentAsChars[i] != '\n') { continue; } firstLine += 1; } return(firstLine > 1); }
public string ToDecl(CgMember cgMem, bool includesAccessModifier = false) { if (cgMem == null) { return(string.Empty); } var cgArgs = cgMem.Args.Select(cgArg => $"{cgArg.ArgType} {cgArg.ArgName}").ToList(); var accessMod = includesAccessModifier ? TransposeCgAccessModToString(cgMem.AccessModifier) + " " : string.Empty; var args = string.Join(", ", cgArgs); if (cgMem.IsCtor) { var ctorName = NfReflect.GetTypeNameWithoutNamespace(cgMem.TypeName); return($"{accessMod}{ctorName}({args})"); } if (cgArgs.Any() || cgMem.IsMethod) { //TODO - this is only going to work for when there is only one generic arg return(cgMem.IsGeneric && !cgMem.IsCtor ? $"{accessMod}{cgMem.TypeName} {cgMem.Name}<{cgMem.TypeName}>({args})" : $"{accessMod}{cgMem.TypeName} {cgMem.Name}({args})"); } var propSyntax = ""; if (cgMem.HasSetter || cgMem.HasGetter) { propSyntax += " { "; if (cgMem.HasGetter) { propSyntax += "get; "; } if (cgMem.HasSetter) { propSyntax += "set; "; } propSyntax += "}"; } return($"{accessMod}{cgMem.TypeName} {cgMem.Name}{propSyntax}"); }
public string ToSignatureRegex(CgMember cgMem) { var regexPattern = new StringBuilder(); regexPattern.Append(@"(\b" + TransposeCgAccessModToString(cgMem.AccessModifier) + @"\b)"); if (cgMem.AccessModifier == CgAccessModifier.Assembly) { regexPattern.Append("?"); } regexPattern.Append(@"([^\x2c\x3b\x7d\x7b]+?)"); regexPattern.AppendFormat(@"\b{0}\b", cgMem.Name); if (cgMem.IsGeneric) { //needs to handle crazy shit like 'global::System.Tuple<int, Func<Mynamespace.MyType, global::System.Int64>>' regexPattern.Append(@"\x3c.*?\x3e"); } if (!cgMem.IsMethod) { return(regexPattern.ToString()); } if (cgMem.Args.Count <= 0) { regexPattern.Append(@"\(\s*?\)"); return(regexPattern.ToString()); } var simpleArgTypes = cgMem.Args.Select( x => @"\s*\b" + NfReflect.GetTypeNameWithoutNamespace(x.ArgType).EscapeString() + @"\b\s*([^\,]+?)").ToList(); regexPattern.AppendFormat(@"\s*\({0}\)", string.Join(@"\,", simpleArgTypes)); return(regexPattern.ToString()); }
public static string ToGraphVizString(this CgArg cgArg) { return(NfReflect.GetTypeNameWithoutNamespace(cgArg.ArgType)); }
//[EditorBrowsable(EditorBrowsableState.Never)] public static List <FlattenedLine> FlattenType(Assembly assembly, string typeFullName, ref int currentDepth, int maxDepth, string limitOnValueType, bool displayEnums, Stack <FlattenedItem> fiValueTypes, Stack typeStack) { var printList = new List <FlattenedLine>(); if (string.IsNullOrWhiteSpace(typeFullName)) { return(printList); } Func <PropertyInfo, string, bool> limitOnPi = (info, s) => string.IsNullOrWhiteSpace(s) || string.Equals($"{info.PropertyType}", s, StringComparison.OrdinalIgnoreCase) || string.Equals(NfReflect.GetLastTypeNameFromArrayAndGeneric(info.PropertyType), s, StringComparison.OrdinalIgnoreCase) || (s == Constants.ENUM && NfReflect.IsEnumType(info.PropertyType)); var currentType = assembly.NfGetType(typeFullName); if (currentType == null) { return(printList); } //top frame of recursive calls will perform this if (fiValueTypes == null) { if (maxDepth <= 0) { maxDepth = 16; } typeStack = new Stack(); typeStack.Push(typeFullName); fiValueTypes = new Stack <FlattenedItem>(); fiValueTypes.Push(new FlattenedItem(currentType) { FlName = NfReflect.GetTypeNameWithoutNamespace(typeFullName) }); } var typeNamesList = currentType.GetProperties(NfSettings.DefaultFlags) .Where( x => (NfReflect.IsValueTypeProperty(x) && limitOnPi(x, limitOnValueType) || (limitOnValueType == Constants.ENUM && limitOnPi(x, limitOnValueType))) //more limbo branching for enums ) .Select(p => new Tuple <Type, string>(p.PropertyType, p.Name)) .ToList(); foreach (var typeNamePair in typeNamesList) { var pVtype = typeNamePair.Item1; var pVname = typeNamePair.Item2; fiValueTypes.Push(new FlattenedItem(pVtype) { FlName = pVname }); var fiItems = fiValueTypes.ToList(); fiItems.Reverse(); printList.Add(new FlattenedLine(fiItems.Distinct(new FlattenedItemComparer()).ToList()) { ValueType = $"{typeNamePair.Item1}" }); fiValueTypes.Pop(); } //then recurse the object types foreach ( var p in currentType.GetProperties(NfSettings.DefaultFlags) .Where(x => !NfReflect.IsValueTypeProperty(x))) { currentDepth += 1; //time to go if (currentDepth >= maxDepth) { return(printList); } var typeIn = NfReflect.GetLastTypeNameFromArrayAndGeneric(p.PropertyType); if (typeIn == null || typeStack.Contains(typeIn)) { continue; } var fi = new FlattenedItem(p.PropertyType) { FlName = p.Name }; if (fiValueTypes.ToList().Any(x => x.FlType == p.PropertyType)) { continue; } fiValueTypes.Push(fi); typeStack.Push(typeIn); //enum types being handled as limbo between value type and ref type string[] enumVals; if (displayEnums && NfReflect.IsEnumType(p.PropertyType, out enumVals)) { foreach (var ev in enumVals) { fiValueTypes.Push(new FlattenedItem(typeof(Enum)) { FlName = ev }); var fiItems = fiValueTypes.ToList(); fiItems.Reverse(); printList.Add(new FlattenedLine(fiItems.Distinct(new FlattenedItemComparer()).ToList()) { ValueType = String.Empty }); fiValueTypes.Pop(); } } else { printList.AddRange(FlattenType(assembly, fi.TypeFullName, ref currentDepth, maxDepth, limitOnValueType, displayEnums, fiValueTypes, typeStack)); } fiValueTypes.Pop(); typeStack.Pop(); currentDepth -= 1; } return(printList); }
/// <summary> /// Parses a hbm.xml file into this runtime equiv. /// being intended for code generation. /// </summary> /// <param name="hbmXmlFilePath"></param> public HbmFileContent(string hbmXmlFilePath) { _simpleProperties = new Dictionary <string, string>(); _fkProperties = new Dictionary <string, string>(); _listProperties = new Dictionary <string, string>(); _compositeKeyProperties = new Dictionary <string, string>(); _keyColumns = new Dictionary <string, ColumnMetadata>(); _simpleColumns = new Dictionary <string, ColumnMetadata>(); _fkColumns = new Dictionary <string, List <ColumnMetadata> >(); _listColumns = new Dictionary <string, List <ColumnMetadata> >(); _spConstNames = new List <HbmStoredProxNames>(); _keyManyToOnePropertyNames = new List <string>(); _allPkColumns = new Dictionary <string, string>(); if (!File.Exists(hbmXmlFilePath)) { throw new ItsDeadJim(string.Format("There isn't any xml file at '{0}'", hbmXmlFilePath)); } _fileNamePath = hbmXmlFilePath; _hbmXml = new XmlDocument(); _hbmXml.LoadXml(File.ReadAllText(_fileNamePath)); _nsMgr = new XmlNamespaceManager(_hbmXml.NameTable); _nsMgr.AddNamespace(NS, Globals.HBM_XML_NS); _classNode = _hbmXml.SelectSingleNode(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS), _nsMgr) as XmlElement; if (_classNode == null) { throw new ItsDeadJim(string.Format("The top-level 'class' node is missing from the xml file at '{0}'", hbmXmlFilePath)); } IsCompositeKey = _hbmXml.SelectSingleNode(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS, HbmXmlNames.COMPOSITE_ID), _nsMgr) != null; var tableNameAttr = _classNode.Attributes[HbmXmlNames.TABLE]; if (tableNameAttr != null) { _tableName = tableNameAttr.Value; } var attrTypeName = GetAttrVal(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS), HbmXmlNames.NAME); if (NfReflect.IsFullAssemblyQualTypeName(attrTypeName)) { _asmQualTypeName = attrTypeName; var nfName = new NfTypeName(attrTypeName); _className = nfName.ClassName; _namespace = nfName.Namespace; } else { _className = NfReflect.GetTypeNameWithoutNamespace(attrTypeName); _namespace = NfReflect.GetNamespaceWithoutTypeName(attrTypeName); _asmQualTypeName = Compose.ClassName(_className, _namespace); } _dbSchema = GetAttrVal(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS), HbmXmlNames.SCHEMA); //the stored prox will not have a schema qualifier so try to derive it from the file name if (string.IsNullOrWhiteSpace(_dbSchema)) { var ff = Path.GetFileName(_fileNamePath); if (!string.IsNullOrWhiteSpace(ff) && ff.Split('.').Length > 3) { _dbSchema = ff.Split('.')[0]; } else { _dbSchema = "Dbo"; } } //get id/composite-id node GetIdNode(); //get id's name and type GetIdName(); //get flat-data's names and types GetFlatProperties(); //get FKs names and types GetFkProperties(); //get IList names and types GetListProperties(); //get stored proc names GetStoredProcNames(); //get composite key's properties GetCompositeKeyProperties(); //condense a list of what is just on this table GetAllPkColumns(); }