Skip to content

Commit 248433a

Browse files
committed
Add textual tree to README, visualizer
1 parent 9b4646f commit 248433a

4 files changed

Lines changed: 36 additions & 26 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ Console.WriteLine(expr.ToString("Object notation"));
4545
ReturnType = typeof(bool)
4646
}
4747
*/
48+
49+
Console.WriteLine(expr.ToString("Textual tree"));
50+
// prints:
51+
/*
52+
Lambda (Func<bool>)
53+
Body - Constant (bool) = True
54+
*/
4855
```
4956

5057
Features:
@@ -54,6 +61,7 @@ Features:
5461
* Pseudo-code in C# or VB.NET
5562
* Factory method calls which generate this expression
5663
* Object notation, using object initializer and collection initializer syntax to describe objects
64+
* Textual tree, focusing on the properties related to the structure of the tree
5765

5866
* Extension methods are rendered as instance methods
5967

Shared/TextualTreeFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private void WriteTextualNode(object o) {
8585
childNodes.ForEach((node, index) => {
8686
if (index > 0) { WriteEOL(); }
8787
Write(node.name);
88-
Write(" -- ");
88+
Write(" - ");
8989
WriteNode(node);
9090
});
9191
Dedent();

Visualizer.Shared/VisualizerDataControl.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public VisualizerDataControl() {
4949
optionsButton.Click += (s1, e1) => optionsPopup.IsOpen = true;
5050
};
5151

52-
cmbFormatters.ItemsSource = new[] { CSharp, VisualBasic, FactoryMethods, ObjectNotation };
52+
cmbFormatters.ItemsSource = new[] { CSharp, VisualBasic, FactoryMethods, ObjectNotation, TextualTree };
5353
cmbLanguages.ItemsSource = new[] { CSharp, VisualBasic };
5454
}
5555

_visualizerTests/Program.cs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static void Main(string[] args) {
2525
//var i = 5;
2626
//Expression<Func<int, int>> expr = j => (i + j + 17) * (i + j + 17);
2727

28-
//Expression<Func<bool>> expr = () => true;
28+
Expression<Func<bool>> expr = () => true;
2929

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

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

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

266-
var personSource = new List<Person>().AsQueryable();
267-
var qry = personSource.Where(x => x.LastName.StartsWith("D"));
268-
var expr = qry.GetType().GetProperty("Expression", NonPublic | Instance).GetValue(qry);
266+
//var personSource = new List<Person>().AsQueryable();
267+
//var qry = personSource.Where(x => x.LastName.StartsWith("D"));
268+
//var expr = qry.GetType().GetProperty("Expression", NonPublic | Instance).GetValue(qry);
269+
270+
//Expression<Func<Person, bool>> expr = p => p.DOB.DayOfWeek == DayOfWeek.Tuesday;
269271

270272
var visualizerHost = new VisualizerDevelopmentHost(expr, typeof(Visualizer), typeof(VisualizerDataObjectSource));
271273
visualizerHost.ShowVisualizer();
272274

273275
//Console.ReadKey(true);
274276

275-
var stream = System.IO.File.Create(System.IO.Path.GetTempFileName());
276-
var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
277-
278-
var data = new VisualizerData(expr);
279-
var t = typeof(VisualizerData);
280-
foreach (var prp in t.GetProperties()) {
281-
try {
282-
formatter.Serialize(stream, prp.GetValue(data));
283-
} catch (Exception) {
284-
Console.WriteLine($"Serialization failed on property {prp.Name}");
285-
}
286-
}
287-
288-
foreach (var fld in t.GetFields()) {
289-
try {
290-
formatter.Serialize(stream, fld.GetValue(data));
291-
} catch (Exception) {
292-
Console.WriteLine($"Serialization failed on field {fld.Name}");
293-
}
294-
}
277+
//var stream = System.IO.File.Create(System.IO.Path.GetTempFileName());
278+
//var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
279+
280+
//var data = new VisualizerData(expr);
281+
//var t = typeof(VisualizerData);
282+
//foreach (var prp in t.GetProperties()) {
283+
// try {
284+
// formatter.Serialize(stream, prp.GetValue(data));
285+
// } catch (Exception) {
286+
// Console.WriteLine($"Serialization failed on property {prp.Name}");
287+
// }
288+
//}
289+
290+
//foreach (var fld in t.GetFields()) {
291+
// try {
292+
// formatter.Serialize(stream, fld.GetValue(data));
293+
// } catch (Exception) {
294+
// Console.WriteLine($"Serialization failed on field {fld.Name}");
295+
// }
296+
//}
295297
}
296298

297299
static Expression<Func<int, int>> expr1 = ((Func<Expression<Func<int, int>>>)(() => {

0 commit comments

Comments
 (0)