public static string GetPlantUml(string cSharpSource) { var syntaxTree = CSharpSyntaxTree.ParseText(cSharpSource); var treeRoot = syntaxTree.GetRoot(); using (var writer = new StringWriter()) { var pumlGenerator = new ClassDiagramGenerator(writer, IndentStr); pumlGenerator.Generate(treeRoot); return(writer.ToString()); } }
private int HandleCommand(string assembly, string outputFolder) { try { //string outputFileName = @"c:\autoany\assemblyclasses.puml"; //using (var filestream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write)) //using (var writer = new StreamWriter(filestream)) //{ // var gen = new ClassDiagramGenerator(writer, " ", Accessibilities.None, true); // gen.Generate(Assembly.GetExecutingAssembly()); //} //return 0; if (!string.IsNullOrEmpty(assembly)) { System.Reflection.Assembly loaded = System.Reflection.Assembly.LoadFrom(assembly); if (loaded != null) { string folderName = Path.GetDirectoryName(assembly); using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream)) { var gen = new ClassDiagramGenerator(writer, " ", Accessibilities.None, true); gen.Generate(loaded); writer.Flush(); string puml = Encoding.ASCII.GetString(stream.ToArray()); File.WriteAllText(Path.ChangeExtension(Path.Combine(folderName, Path.GetFileName(assembly)), ".puml"), puml); string imageFileName = Path.ChangeExtension(Path.Combine(folderName, Path.GetFileName(assembly)), ".png"); ToPng(puml, imageFileName); ShowImage(imageFileName); } } } } catch (Exception ex) { Console.WriteLine(ex); return(1); } return(0); }
public void GenerateTestWithoutPrivate() { var code = File.ReadAllText("testData\\inputClasses.cs"); var tree = CSharpSyntaxTree.ParseText(code); var root = tree.GetRoot(); var output = new StringBuilder(); using (var writer = new StringWriter(output)) { var gen = new ClassDiagramGenerator(writer, " ", Accessibilities.Private); gen.Generate(root); } var expected = ConvertNewLineCode(File.ReadAllText(@"uml\withoutPrivate.puml"), Environment.NewLine); var actual = output.ToString(); Console.Write(actual); Assert.AreEqual(expected, actual); }
public void NullableTestNullableTypes() { var code = File.ReadAllText(Path.Combine("testData", "NullableType.cs")); var tree = CSharpSyntaxTree.ParseText(code); var root = tree.GetRoot(); var output = new StringBuilder(); using (var writer = new StringWriter(output)) { var gen = new ClassDiagramGenerator(writer, " ", Accessibilities.Private | Accessibilities.Internal | Accessibilities.Protected | Accessibilities.ProtectedInternal); gen.Generate(root); } var expected = ConvertNewLineCode(File.ReadAllText(Path.Combine("uml", "nullableType.puml")), Environment.NewLine); var actual = output.ToString(); Console.Write(actual); Assert.AreEqual(expected, actual); }
public AsciiDiagramTest() { _classDiagramGenerator = GeneratorFactory.Create <string>(); }
public ParseTest() { _classDiagramGenerator = GeneratorFactory.Create <string>(); }