Print tree
The extension method IRequest.PrintTree() prints a request into tree format. This is useful for evaluation and debugging.
// Request to create type builder
IRequestFor<TypeBuilder> typeBuilderRequest = new TypeBuilderRequest("MyClass88");
// Request to build type
IRequestFor<Type> typeRequest = new TypeRequest(typeBuilderRequest);
// Request for new instance
IRequestFor<Object> newRequest = typeRequest.NewRequest();
// Formulate to text
string text = newRequest.PrintTree();
// Write text
Console.WriteLine(text);
NewRequest └── Type = TypeRequest └── Key = TypeBuilderRequest ├── Name = "MyClass88" └── Attributes = AutoLayout, AnsiClass, Class, Public, AutoClass
Another version IRequest.PrintTreeTo(TextWriter) writes directly to TextWriter.
// Print to TextWriter
newRequest.PrintTreeTo(Console.Out);
Full Example
Full example
using System;
using System.Reflection.Emit;
using Avalanche.Emit;
using Avalanche.Service;
public class request_printtree
{
public static void Run()
{
// <01>
// Request to create type builder
IRequestFor<TypeBuilder> typeBuilderRequest = new TypeBuilderRequest("MyClass88");
// Request to build type
IRequestFor<Type> typeRequest = new TypeRequest(typeBuilderRequest);
// Request for new instance
IRequestFor<Object> newRequest = typeRequest.NewRequest();
// Formulate to text
string text = newRequest.PrintTree();
// Write text
Console.WriteLine(text);
// </01>
// <02>
// Print to TextWriter
newRequest.PrintTreeTo(Console.Out);
// </02>
}
}