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 Uml2Code(IEnumerable <string> paths, string _target) { foreach (string path in paths) { string target = _target.Length > 0 ? _target + "/" : path + "/codegen/"; Console.WriteLine(path); List <IUmlObject> objects = new List <IUmlObject> (); Action <string> processFile = (filename) => { IParser parser = new UmlParser(); objects.AddRange(parser.Parse(filename)); }; Files.SearchFiles(path, new string[] { ".uml" }, processFile); foreach (IUmlObject obj in objects) { List <string> lines = new List <string> (); lines.Add(obj.ToCSharpCode() + "\n"); string genfile = target + Packages.GetPackage(obj.Name).Replace(".", "/") + "/" + obj.Name.Clean() + ".cs"; Console.WriteLine("Write: " + genfile); Files.WriteLines(genfile, lines); } } }
public override string ToTexCode() { if (Content.Length == 0) { return(""); } string typestr = type == ClassType.Interface ? "Schnittstelle" : "Klasse"; List <string> lines = new List <string> (); lines.Add(@"\subsubsection{" + typestr + @" " + name + @"}\index{" + Packages.GetPackage(name) + "!" + name + @"}\label{" + name + "}"); // wrapfigure //lines.Add (@"\begin{wrapfigure}{R}{9cm}{0}" + "\n" + @"\centering"); //lines.Add (@"\includegraphics[scale=0.5]{Klassen/" + Name.Clean () + @"}"); //lines.Add (@"\end{wrapfigure}"); // in der mitte lines.Add(@"\begin{figure}[h!]" + "\n" + @"\centering"); lines.Add(@"\includegraphics[scale=1]{Klassen/" + Name.Clean() + @"}"); lines.Add(@"\end{figure}"); lines.Add(@"\paragraph{Beschreibung:}\mbox{}\newline\newline"); foreach (string cmt in Comments.GetComments(commentsKey)) { if (cmt.StartsWith("[") && cmt.EndsWith("]") && cmt.Contains("=")) { continue; } lines.Add(Packages.AddTexCommands(cmt)); } //lines.Add (@"\setlength{\columnsep}{10pt}%"); lines.Add("\n"); 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(@"\paragraph{Eigenschaften:}\mbox{} \newline\newline"); bool first = true; foreach (UmlAttribute obj in attributes) { if (!first) { lines.Add(@"~\\\\"); } lines.Add(obj.ToTexCode()); first = false; } //lines.Add (@"\end{description}"); } if (contructors.Count() > 0) { // lines.Add (@"\paragraph{Konstruktoren:}\mbox{} \begin{description} "); lines.Add(@"\paragraph{Konstruktoren:}\mbox{} \newline\newline"); bool first = true; foreach (UmlMethod obj in contructors) { if (!first) { lines.Add(@"~\\\\"); } obj.IsContructor = true; lines.Add(obj.ToTexCode()); first = false; } //lines.Add (@"\end{description}"); } if (methods.Count() > 0) { // lines.Add (@"\paragraph{Methoden:}\mbox{} \begin{description} "); lines.Add(@"\paragraph{Methoden:}\mbox{} \newline\newline"); bool first = true; foreach (UmlMethod obj in methods) { if (!first) { lines.Add(@"~\\\\"); } lines.Add(obj.ToTexCode()); first = false; } // lines.Add (@"\end{description}"); } return(string.Join("\n", lines).Replace("<", "$<$").Replace(">", "$>$")); }
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)); }