public override string ToCSharpCode(int padding = 0) { string paddingStr = String.Concat(Enumerable.Repeat(" ", padding)); List <string> lines = new List <string> (); lines.AddRange(Packages.GetUsingStatements(Packages.GetPackage(name))); if (Packages.IsInPackage(name)) { lines.Add(paddingStr + "namespace " + Packages.GetPackage(name)); lines.Add(paddingStr + "{"); paddingStr += " "; padding += 4; } lines.AddRange(Comments.CSharpComments(commentsKey, paddingStr)); lines.Add(paddingStr + Publicity.ToCode("", " ") + Virtuality.ToCode("", " ") + "enum " + name); lines.Add(paddingStr + "{"); foreach (string literal in values) { lines.AddRange(Comments.CSharpComments(Comments.Key(name, literal), paddingStr + " ")); lines.Add(paddingStr + " " + literal + ","); } lines.Add(paddingStr + "}"); if (Packages.IsInPackage(name)) { padding -= 4; paddingStr = paddingStr.Substring(4); lines.Add(paddingStr + "}"); } return(string.Join("\n", lines)); }
public override string ToUmlCode(int padding = 0) { string paddingStr = String.Concat(Enumerable.Repeat(" ", padding)); List <string> lines = new List <string> (); lines.AddRange(Comments.PrintComments(commentsKey, paddingStr)); string nameWithPackage = Packages.IsInPackage(name) ? Packages.GetPackage(name) + "." + name : name; lines.Add( paddingStr + Publicity.ToCode("", " ") + Virtuality.ToCode("", " ") + type.ToCode("", " ") + nameWithPackage + " : " + string.Join(", ", bases) ); lines.Add(paddingStr + " Attributes:"); foreach (IUmlObject obj in Content) { if (obj is UmlAttribute) { lines.Add(obj.ToUmlCode(padding + 4)); } } lines.Add(paddingStr + " Methods:"); foreach (IUmlObject obj in Content) { if (!(obj is UmlAttribute)) { lines.Add(obj.ToUmlCode(padding + 4)); } } return(string.Join("\n", lines)); }
public override string ToUmlCode(int padding = 0) { string paddingStr = String.Concat(Enumerable.Repeat(" ", padding)); List <string> lines = new List <string> (); lines.AddRange(Comments.PrintComments(commentsKey, paddingStr)); string nameWithPackage = Packages.IsInPackage(name) ? Packages.GetPackage(name) + "." + name : name; lines.Add(paddingStr + Publicity.ToCode("", " ") + Virtuality.ToCode("", " ") + "enum " + nameWithPackage); foreach (string literal in values) { lines.AddRange(Comments.PrintComments(Comments.Key(name, literal), paddingStr + " ")); lines.Add(paddingStr + " " + literal); } return(string.Join("\n", lines)); }
private static void Uml2Tex(IEnumerable <string> umlfiles, string target) { List <IUmlObject> allObjects = new List <IUmlObject> (); foreach (string umlfile in umlfiles) { IParser parser = new UmlParser(); Console.WriteLine("Read: " + umlfile); allObjects.AddRange(parser.Parse(umlfile)); } Console.WriteLine("Write: " + target); List <string> lines = new List <string> (); lines.AddRange(UmlObject.TexHeader); foreach (string package in Packages.PackageMap.Keys) { lines.Add(@"\section{Paket " + package + @"}"); lines.Add(@"\subsection{Klassen}"); foreach (UmlClass obj in allObjects.OfType <UmlClass>().Where((c) => Packages.IsInPackage(package, c.Name))) { if (obj.type != ClassType.Interface) { lines.Add(obj.ToTexCode()); lines.Add(""); } } lines.Add(@"\subsection{Schnittstellen}"); foreach (UmlClass obj in allObjects.OfType <UmlClass>().Where((c) => Packages.IsInPackage(package, c.Name))) { if (obj.type == ClassType.Interface) { lines.Add(obj.ToTexCode()); lines.Add(""); } } lines.Add(@"\subsection{Enumerationen}"); foreach (UmlEnum obj in allObjects.OfType <UmlEnum>().Where((c) => Packages.IsInPackage(package, c.Name))) { lines.Add(obj.ToTexCode()); lines.Add(""); } } Files.WriteLines(target, lines); lines.Clear(); newCommand(ref lines, "CountClasses", "" + allObjects.OfType <UmlClass> () .Where((o) => o.type == ClassType.Class).Count() ); newCommand(ref lines, "CountInterfaces", "" + allObjects.OfType <UmlClass> () .Where((o) => o.type == ClassType.Interface).Count() ); newCommand(ref lines, "CountEnums", "" + allObjects.OfType <UmlEnum> () .Count() ); newCommand(ref lines, "CountAll", "" + (allObjects.OfType <UmlClass> () .Where((o) => o.type == ClassType.Class).Count() + allObjects.OfType <UmlClass> () .Where((o) => o.type == ClassType.Interface).Count() + allObjects.OfType <UmlEnum> () /* Strukturen? */ .Count()) ); Files.WriteLines(Path.GetDirectoryName(target) + "/Definitionen.gentex", lines); if (IsRunningOnMono()) { foreach (UmlClass obj in allObjects.OfType <UmlClass>()) { // write class diagram ClassDiagram dia = new ClassDiagram(new IUmlObject[] { obj }); string filename = Path.GetDirectoryName(target) + "/Klassen/" + obj.Name.Clean(); Files.WriteLines(filename + ".dot", dia.DotCode("", "ffffff", 200)); //GraphViz.Dot ("svg", filename + ".dot", filename + ".svg"); //GraphViz.Dot ("jpg", filename + ".dot", filename + ".jpg"); //GraphViz.Dot ("png", filename + ".dot", filename + ".png"); GraphViz.Dot("svg", filename + ".dot", filename + ".svg"); //GraphViz.Convert ("-density 100", "svg:" + filename + ".svg", filename + ".png"); //GraphViz.RsvgConvert ("--dpi-x 120", "--dpi-y 120", filename + ".svg", ">", filename + ".png"); GraphViz.InkScape("--export-png=" + filename + ".png", "--export-dpi=150", filename + ".svg"); } } }
public override string ToCSharpCode(int padding = 0) { string paddingStr = String.Concat(Enumerable.Repeat(" ", padding)); List <string> lines = new List <string> (); lines.AddRange(Packages.GetUsingStatements(Packages.GetPackage(name))); if (Packages.IsInPackage(name)) { lines.Add(paddingStr + "namespace " + Packages.GetPackage(name)); lines.Add(paddingStr + "{"); paddingStr += " "; padding += 4; } lines.AddRange(Comments.CSharpComments(commentsKey, paddingStr)); lines.Add( paddingStr + Publicity.ToCode("", " ") + Virtuality.ToCode("", " ") + type.ToCode("", " ") + name + (bases.Length > 0 ? " : " + string.Join(", ", bases).Replace("XNA.", "") : "") ); lines.Add(paddingStr + "{"); lines.Add(""); IEnumerable <UmlAttribute> attributes = Content.OfType <UmlAttribute> (); IEnumerable <UmlMethod> contructors = Content.OfType <UmlMethod> ().Where((m) => m.Name == Name); IEnumerable <UmlMethod> methods = Content.OfType <UmlMethod> ().Where((m) => m.Name != Name); if (attributes.Count() > 0) { lines.Add(paddingStr + " #region Properties"); lines.Add(""); foreach (UmlAttribute obj in attributes) { lines.Add(obj.ToCSharpCode(padding + 4, Virtuality.Virtual, this)); lines.Add(""); } lines.Add(paddingStr + " #endregion"); lines.Add(""); } if (contructors.Count() > 0) { lines.Add(paddingStr + " #region Constructors"); lines.Add(""); foreach (UmlMethod obj in contructors) { obj.IsContructor = true; lines.Add(obj.ToCSharpCode(padding + 4, Virtuality.None, this)); lines.Add(""); } lines.Add(paddingStr + " #endregion"); lines.Add(""); } if (methods.Count() > 0) { lines.Add(paddingStr + " #region Methods"); lines.Add(""); foreach (UmlMethod obj in methods) { lines.Add(obj.ToCSharpCode(padding + 4, Virtuality.Virtual, this)); lines.Add(""); } lines.Add(paddingStr + " #endregion"); lines.Add(""); } lines.Add(paddingStr + "}"); if (Packages.IsInPackage(name)) { padding -= 4; paddingStr = paddingStr.Substring(4); lines.Add(paddingStr + "}"); } return(string.Join("\n", lines)); }