Skip to content

Commit

Permalink
Add textual tree to README, visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitz committed Aug 14, 2019
1 parent 9b4646f commit 248433a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ Console.WriteLine(expr.ToString("Object notation"));
ReturnType = typeof(bool)
}
*/

Console.WriteLine(expr.ToString("Textual tree"));
// prints:
/*
Lambda (Func<bool>)
Body - Constant (bool) = True
*/
```

Features:
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Shared/TextualTreeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Visualizer.Shared/VisualizerDataControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down
50 changes: 26 additions & 24 deletions _visualizerTests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static void Main(string[] args) {
//var i = 5;
//Expression<Func<int, int>> expr = j => (i + j + 17) * (i + j + 17);

//Expression<Func<bool>> expr = () => true;
Expression<Func<bool>> expr = () => true;

//Expression<Func<string, int, string>> expr = (s, i) => $"{s}, {i}";

Expand Down Expand Up @@ -263,35 +263,37 @@ static void Main(string[] args) {

//Expression<Func<string>> expr = () => string.IsInterned("");

var personSource = new List<Person>().AsQueryable();
var qry = personSource.Where(x => x.LastName.StartsWith("D"));
var expr = qry.GetType().GetProperty("Expression", NonPublic | Instance).GetValue(qry);
//var personSource = new List<Person>().AsQueryable();
//var qry = personSource.Where(x => x.LastName.StartsWith("D"));
//var expr = qry.GetType().GetProperty("Expression", NonPublic | Instance).GetValue(qry);

//Expression<Func<Person, bool>> 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<Func<int, int>> expr1 = ((Func<Expression<Func<int, int>>>)(() => {
Expand Down

0 comments on commit 248433a

Please sign in to comment.