Print Tree
Extension method .PrintTree() prints a tree representation of IIdentity.
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance, NetTypeHandlers.Instance));
// Create request for Dictionary
DataTypeRequest<NetMap> request = new(typeof(IDictionary<string, int>));
// Query datatype for Dictionary
IDataType datatype = service.GetRequired<IRequest, IDataType>(request);
// Print datatype
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.Default));
'format:' can be provided as argument.
DataTypePrintTreeExtensions.PrintFormat.Topology
IMapType ├── IStringType │ └── IIntegerType └── IIntegerType
DataTypePrintTreeExtensions.PrintFormat.TopologyLong
System.Collections.Generic.IDictionary`2[[System.String],[System.Int32]] : IMapType ├── string : IStringType │ └── char : IIntegerType └── int : IIntegerType
DataTypePrintTreeExtensions.PrintFormat.DefaultVeryShort
System.Collections.Generic.IDictionary`2[[System.String],[System.Int32]] ├── string │ └── char └── int
DataTypePrintTreeExtensions.PrintFormat.DefaultShort
System.Collections.Generic.IDictionary`2[[System.String],[System.Int32]] ├── Key = string │ └── Element = char └── Value = int
DataTypePrintTreeExtensions.PrintFormat.Default
System.Collections.Generic.IDictionary`2[[System.String],[System.Int32]] : IMapType ├── Key = string : IStringType │ └── Element = char : IIntegerType └── Value = int : IIntegerType
DataTypePrintTreeExtensions.PrintFormat.DefaultLong
IMapType { Name = "System.Collections.Generic.IDictionary`2[[System.String],[System.Int32]]" , Nullable = True, Referable = True, Annotations = [System.Runtime.CompilerServices.NullableContextAttribute, System.Reflection.DefaultMemberAttribute] } ├── Key = IStringType { Name = "string" , Encoding = "Unicode", Nullable = True, Referable = True, Description = "Unicode UTF-16", Annotations = [], MinLength = 0, MaxLength = 2147483647 } │ └── Element = IIntegerType { Name = "char" , SignCapability = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = , MinValue = 0, MaxValue = 65535 } └── Value = IIntegerType { Name = "int" , Base = 2, SignificandPrecision = 32, SignCapability = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -2147483648, MaxValue = 2147483647 }
DataTypePrintTreeExtensions.PrintFormat.DefaultVeryLong
IMapType { Name = "System.Collections.Generic.IDictionary`2[[System.String],[System.Int32]]" , Nullable = True, Referable = True, Description = null, Annotations = [System.Runtime.CompilerServices.NullableContextAttribute, System.Reflection.DefaultMemberAttribute], DefaultValue = null } ├── Key = IStringType { Name = "string" , Pattern = null, Encoding = "Unicode", Nullable = True, Referable = True, Description = "Unicode UTF-16", Annotations = [], DefaultValue = null, MinLength = 0, MaxLength = 2147483647 } │ └── Element = IIntegerType { Name = "char" , Base = null, SignificandPrecision = null, SignCapability = False, Nullable = False, Referable = False, Description = null, Annotations = [], DefaultValue = , Unit = null, MinValue = 0, MaxValue = 65535 } └── Value = IIntegerType { Name = "int" , Base = 2, SignificandPrecision = 32, SignCapability = True, Nullable = False, Referable = False, Description = null, Annotations = [], DefaultValue = 0, Unit = null, MinValue = -2147483648, MaxValue = 2147483647 }
Data types that are cyclic are printed up until type reoccurs.
public sealed class Node
{
public readonly int Id;
public List<Node> Edges = new List<Node>();
public Node(int id) => Id = id;
}
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance, NetTypeHandlers.Instance));
// Create request
DataTypeRequest<NetRecord> request = new(typeof(Node));
// Query datatype
IDataType datatype = service.GetRequired<IRequest, IDataType>(request);
// Print datatype
WriteLine(datatype.PrintTree());
Node, docs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null : IAnyType └── Node, docs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null : IRecordType ├── Id : IFieldType │ └── int : IIntegerType └── Edges : IFieldType └── System.Collections.Generic.List`1[[Node]] : IListType └── Node, docs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null : IAnyType
.VisitTree() extension methods visits tree branches.
// Visit tree branches
foreach (var line in datatype.VisitTree())
{
WriteLine(line.DataType.Name());
}
Full Example
Full example
using System.Collections.Generic;
using Avalanche.DataType;
using Avalanche.Service;
using static System.Console;
public class printtree
{
public static void Run()
{
{
// <01>
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance, NetTypeHandlers.Instance));
// Create request for Dictionary
DataTypeRequest<NetMap> request = new(typeof(IDictionary<string, int>));
// Query datatype for Dictionary
IDataType datatype = service.GetRequired<IRequest, IDataType>(request);
// Print datatype
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.Default));
// </01>
// <DefaultVeryLong>
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultVeryLong));
// </DefaultVeryLong>
// <DefaultLong>
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
// </DefaultLong>
// <Default>
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.Default));
// </Default>
// <DefaultShort>
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultShort));
// </DefaultShort>
// <DefaultVeryShort>
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultVeryShort));
// </DefaultVeryShort>
// <Topology>
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.Topology));
// </Topology>
// <TopologyLong>
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.TopologyLong));
// </TopologyLong>
}
{
// <03>
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance, NetTypeHandlers.Instance));
// Create request
DataTypeRequest<NetRecord> request = new(typeof(Node));
// Query datatype
IDataType datatype = service.GetRequired<IRequest, IDataType>(request);
// Print datatype
WriteLine(datatype.PrintTree());
// </03>
// <04>
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultVeryLong));
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.Default));
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultShort));
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultVeryShort));
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.Topology));
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.TopologyLong));
// </04>
}
{
// Create service
IService service = Services.Create((ServiceHandlers.Instance, DataTypeHandlers.Instance, NetTypeHandlers.Instance));
// Create request
DataTypeRequest<NetRecord> request = new(typeof(Node));
// Query datatype
IDataType datatype = service.GetRequired<IRequest, IDataType>(request);
// <21>
// Visit tree branches
foreach (var line in datatype.VisitTree())
{
WriteLine(line.DataType.Name());
}
// </21>
}
}
}
// <99>
public sealed class Node
{
public readonly int Id;
public List<Node> Edges = new List<Node>();
public Node(int id) => Id = id;
}
// </99>