From 248433af49cb63c1c1f2fe96b95b4745a8c03e5c Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Thu, 15 Aug 2019 02:27:30 +0300 Subject: [PATCH] Add textual tree to README, visualizer --- README.md | 8 +++ Shared/TextualTreeFormatter.cs | 2 +- .../VisualizerDataControl.xaml.cs | 2 +- _visualizerTests/Program.cs | 50 ++++++++++--------- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index ad0727b..fd7a277 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,13 @@ Console.WriteLine(expr.ToString("Object notation")); ReturnType = typeof(bool) } */ + +Console.WriteLine(expr.ToString("Textual tree")); +// prints: +/* + Lambda (Func) + Body - Constant (bool) = True +*/ ``` Features: @@ -54,6 +61,7 @@ Features: * Pseudo-code in C# or VB.NET * Factory method calls which generate this expression * Object notation, using object initializer and collection initializer syntax to describe objects + * Textual tree, focusing on the properties related to the structure of the tree * Extension methods are rendered as instance methods diff --git a/Shared/TextualTreeFormatter.cs b/Shared/TextualTreeFormatter.cs index 14a242f..94bec55 100644 --- a/Shared/TextualTreeFormatter.cs +++ b/Shared/TextualTreeFormatter.cs @@ -85,7 +85,7 @@ private void WriteTextualNode(object o) { childNodes.ForEach((node, index) => { if (index > 0) { WriteEOL(); } Write(node.name); - Write(" -- "); + Write(" - "); WriteNode(node); }); Dedent(); diff --git a/Visualizer.Shared/VisualizerDataControl.xaml.cs b/Visualizer.Shared/VisualizerDataControl.xaml.cs index ab5d239..201383d 100644 --- a/Visualizer.Shared/VisualizerDataControl.xaml.cs +++ b/Visualizer.Shared/VisualizerDataControl.xaml.cs @@ -49,7 +49,7 @@ public VisualizerDataControl() { optionsButton.Click += (s1, e1) => optionsPopup.IsOpen = true; }; - cmbFormatters.ItemsSource = new[] { CSharp, VisualBasic, FactoryMethods, ObjectNotation }; + cmbFormatters.ItemsSource = new[] { CSharp, VisualBasic, FactoryMethods, ObjectNotation, TextualTree }; cmbLanguages.ItemsSource = new[] { CSharp, VisualBasic }; } diff --git a/_visualizerTests/Program.cs b/_visualizerTests/Program.cs index b4458da..84ad9e8 100644 --- a/_visualizerTests/Program.cs +++ b/_visualizerTests/Program.cs @@ -25,7 +25,7 @@ static void Main(string[] args) { //var i = 5; //Expression> expr = j => (i + j + 17) * (i + j + 17); - //Expression> expr = () => true; + Expression> expr = () => true; //Expression> expr = (s, i) => $"{s}, {i}"; @@ -263,35 +263,37 @@ static void Main(string[] args) { //Expression> expr = () => string.IsInterned(""); - var personSource = new List().AsQueryable(); - var qry = personSource.Where(x => x.LastName.StartsWith("D")); - var expr = qry.GetType().GetProperty("Expression", NonPublic | Instance).GetValue(qry); + //var personSource = new List().AsQueryable(); + //var qry = personSource.Where(x => x.LastName.StartsWith("D")); + //var expr = qry.GetType().GetProperty("Expression", NonPublic | Instance).GetValue(qry); + + //Expression> expr = p => p.DOB.DayOfWeek == DayOfWeek.Tuesday; var visualizerHost = new VisualizerDevelopmentHost(expr, typeof(Visualizer), typeof(VisualizerDataObjectSource)); visualizerHost.ShowVisualizer(); //Console.ReadKey(true); - var stream = System.IO.File.Create(System.IO.Path.GetTempFileName()); - var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); - - var data = new VisualizerData(expr); - var t = typeof(VisualizerData); - foreach (var prp in t.GetProperties()) { - try { - formatter.Serialize(stream, prp.GetValue(data)); - } catch (Exception) { - Console.WriteLine($"Serialization failed on property {prp.Name}"); - } - } - - foreach (var fld in t.GetFields()) { - try { - formatter.Serialize(stream, fld.GetValue(data)); - } catch (Exception) { - Console.WriteLine($"Serialization failed on field {fld.Name}"); - } - } + //var stream = System.IO.File.Create(System.IO.Path.GetTempFileName()); + //var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + + //var data = new VisualizerData(expr); + //var t = typeof(VisualizerData); + //foreach (var prp in t.GetProperties()) { + // try { + // formatter.Serialize(stream, prp.GetValue(data)); + // } catch (Exception) { + // Console.WriteLine($"Serialization failed on property {prp.Name}"); + // } + //} + + //foreach (var fld in t.GetFields()) { + // try { + // formatter.Serialize(stream, fld.GetValue(data)); + // } catch (Exception) { + // Console.WriteLine($"Serialization failed on field {fld.Name}"); + // } + //} } static Expression> expr1 = ((Func>>)(() => {