• Avalanche.Core
Search Results for

    Show / Hide Table of Contents
    • Avalanche.Accessor
      • Introduction
      • IAccessor
        • IAccessor
        • IListAccessor
        • IMapAccessor
        • IRecordAccessor
        • IContentAccessor
        • IOneOfAccessor
        • IAnyAccessor
      • .Net
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Protobuf
        • Introduction
      • Articles
        • Dependency Injection
        • AccessorMessages
    • Avalanche.Binding
      • Introduction
    • Avalanche.Configuration
      • Introduction
      • Configuration Binding
      • ConfigurationExtensions
      • MemoryConfiguration
      • PrintTree
      • Saving IOptions
      • Yaml
    • Avalanche.Converter
      • Introduction
      • EnumConverter
      • Func<,>
      • HexConverter
      • PrimitiveConverter
      • StringConverter
    • Avalanche.Core
      • License
    • Avalanche.DataType
      • Introduction
      • DataType
        • IDataType
        • IListType
        • IMapType
        • IRecordType
        • IFieldType
        • IOneOfType
        • IAnyType
        • IStringType
        • IValueType
        • IIntegerType
        • IEnumerationType
        • IRealType
      • .Net
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • Enum
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Protobuf
        • Introduction
      • Articles
        • DataTypeRequest
        • PrintTree
        • DataTypeMessages
    • Avalanche.Emit
      • Introduction
      • TypeBuilder
      • ConstructorBuilder
      • MethodBuilder
      • PropertyBuilder
      • FieldBuilder
      • Emit
      • Utilities
    • Avalanche.FileSystem
      • Introduction
      • Abstractions
        • IFileSystem
          • IFileSystemBrowse
          • IFileSystemCreateDirectory
          • IFileSystemDelete
          • IFileSystemFileAttribute
          • IFileSystemMount
          • IFileSystemMove
          • IFileSystemObserve
          • IFileSystemOpen
        • IEvent
        • IEntry
        • IOption
        • IToken
      • FileSystem
      • VirtualFileSystem
      • MemoryFileSystem
      • EmbeddedFileSystem
      • HttpFileSystem
      • Decoration
      • IFileProvider
      • Events
      • Utilities
        • Dispose
        • File Scanner
        • Visit Tree
        • File Operation
        • FilterEnumerable
        • PollingFilterWatchToken
    • Avalanche.Identity
      • Introduction
      • Identity
      • IdentityParts
      • IdentityInterner
      • IdentityComparer
      • Print Tree
      • IdentityAccessors
        • Introduction
        • TypeName
    • Avalanche.Localization
      • Introduction
      • Localization
      • LocalizationFile
      • LocalizationFiles
      • LocalizationFileSystem
      • LocalizationFileFormat
      • LocalizationLine
      • LocalizationLines
      • TemplateFormat
      • CultureProvider
      • FallbackCultureProvider
      • ResourceManager
      • LocalizationError
      • Microsoft.Extensions
        • Introduction
        • DependencyInjection
        • FileProvider
        • Logging
        • ITextLocalizer
        • IFileLocalizer
        • Localization
      • Asp.Net
        • Introduction
        • Supplying localization
        • Inject to pages
        • Culture Assigned
        • Minimalistic Api
        • Diagnostics
      • Pluralization
        • Introduction
        • Multiple plural parameters
        • Custom PluralRules
        • Invariant Culture
        • Unit Prefix
        • IPluralRule
        • IPluralNumber
        • IPluralRules
        • CLDRs
        • Unicode.CLDR40
        • Unicode.CLDR41
        • Unicode.CLDR42
      • Articles
        • Alphabet localization
        • Benchmarks
        • Caching
        • Class Library
        • Demo
        • Diagnostics
        • Embedded resources
        • Emplacement
        • File localization
        • Text localization
        • Printing templates
    • Avalanche.Message
      • Introduction
      • IMessage
      • IMessageProvider
      • IMessageDescription
      • IMessageDescriptions
      • MessageLevel
      • Message printing
      • Messages and Exceptions
      • Microsoft.Extensions
        • DependencyInjection
      • Articles
        • Aggregate Messages
        • Localization
        • Logging
        • Validation
    • Avalanche.Options
      • Introduction
      • OptionsExtensions
      • OptionsMonitorCast
    • Avalanche.Service
      • Introduction
      • Service
        • Introduction
        • IService
        • IServiceDisposable
        • IServiceDecoration
        • IServiceCast
        • IServiceObservable
        • IServiceContainer
        • Construction
        • Query
        • CancellationToken
        • CachePolicy
        • Scope
      • Handler
        • Introduction
        • IHandler
        • IHandlerCast
        • IHandlerDecoration
        • IHandlerWithOrder
        • CancellationToken
        • Cyclicity
        • Delegates
        • Invokable
        • ExportAttribute
        • OrderAttribute
        • PrintTree
        • Recursion
      • Query
        • Introduction
        • IQuery
        • IQueryCast
        • IQueryDecoration
      • Entry
        • Introduction
        • IEntry
        • IEntryCast
        • IEntryDecoration
        • IEntryObservable
        • IEntryVisitable
        • EntryState
      • Request
        • Introduction
        • IRequest
        • IRequestFor
        • IRequestToBeCached
        • IRequestToBeDisposed
        • RequestAttribute
        • ContextParameterAttribute
        • Print Tree
      • Dependency Injection
        • Introduction
        • Asp.Net
        • ServiceRequest<T>
        • Decorating a service
        • Handler
        • CachePolicy
        • CancellationToken
        • QueryLogger
        • IHostBuilder
      • Examples
        • NodeCount
        • Expression
        • Mapper
      • Articles
        • Benchmarks
        • Error Handling
        • ServiceMessages
    • Avalanche.StatusCode
      • Introduction
      • HResult
        • Introduction
        • HResult.Facilities
        • BasicMessages
        • RpcMessages
        • DispatchMessages
        • StorageMessages
        • ItfMessages
        • Win32Messages
        • WindowsMessages
        • SspiMessages
        • CertMessages
        • MediaServerMessages
        • SetupApiMessages
        • ScardMessages
        • ComPlusMessages
        • ClrMessages
        • UserModeFilterManagerMessages
        • GraphicsMessages
        • TpmServicesMessages
        • TpmSoftwareMessages
        • PlaMessages
        • FveMessages
        • FwpMessages
        • NdisMessages
        • DltMessages
      • System
        • Introduction
        • AccessControlMessages
        • AggregateMessages
        • AppDomainMessages
        • ArgumentMessages
        • ArgumentNullMessages
        • ArgumentOutOfRangeMessages
        • ArithmeticMessages
        • ArrayMessages
        • AssemblyMessages
        • BadImageFormatMessages
        • CodeContractMessages
        • CodePageMessages
        • CollectionsMessages
        • CompilerServiceMessages
        • CryptographyMessages
        • CultureMessages
        • DiagnosticsMessages
        • EventSourceMessages
        • ExecutionEngineMessages
        • FormatMessages
        • HostProtectionMessages
        • IOMessages
        • IndexOutOfRangeMessages
        • InteropServiceMessages
        • InvalidCastMessages
        • InvalidOperationMessages
        • IsolatedStorageMessages
        • LazyMessages
        • MarshalerMessages
        • MemoryMessages
        • MiscellaneousMessages
        • NotImplementedMessages
        • NotSupportedMessages
        • ObjectDisposedMessages
        • OperationCanceledMessages
        • OverflowMessages
        • PlatformMessages
        • PolicyMessages
        • PrincipalMessages
        • ProgramMessages
        • ReferenceMessages
        • ReflectionMessages
        • RegionMessages
        • RemotingMessages
        • ResourcesMessages
        • SecurityMessages
        • SerializationMessages
        • StackMessages
        • TaskMessages
        • TextMessages
        • ThreadingMessages
        • TimeZoneMessages
        • TypeMessages
        • XmlMessages
      • HttpStatusCode
      • OpcUaStatusCode
    • Avalanche.Template
      • Introduction
      • TemplateFormats
      • ITemplatePrintable
      • ITemplateFormatPrintable
      • ITemplateText
      • ITemplateBreakdown
      • ITemplateFormat
      • ITemplateFormats
      • Extract Arguments
      • Emplacement
    • Avalanche.Tokenizer
      • Introduction
      • IToken
      • ITokenizer
      • Tokenizers
    • Avalanche.Utilities
      • Introduction
      • Collections
        • Tuples
        • StructList
        • ArrayList
        • BijectionMap
        • LocakableDictionary
        • LockableList
        • MapList
        • Pipe
        • RingQueue
        • EnumerableExtensions
        • TupleUtilities
        • ArrayUtilities
      • Comparers
        • IGraphComparer
        • IGraphComparable
        • AlphaNumericComparer
        • EnumerableComparer
        • EnumerableGraphComparer
        • ReferenceComparer
        • KeyValuePairComparer
        • DefaultComparerProvider
        • RecordComparer
      • Cloners
        • ICloner
        • IGraphCloner
        • IGraphCloneable
        • ListCloner
        • DictionaryCloner
        • FieldCloner
        • PassthroughCloner
        • RecordCloner
        • ClonerProvider
      • Dispose
        • IDisposeAttachable
        • IDisposeBelatable
      • Provider
        • Introduction
        • ProviderBase
        • Delegate
        • Pipe
        • Cache
        • ResultCapture
        • AsReadOnly
        • AsService
        • IProviderEvent
      • Record
        • IRecordDescription
        • IFieldDescription
        • IConstructorDescription
        • IConstructionDescription
        • IParameterDescription
        • IRecordProviders
        • RecordDelegates
          • RecordCreate
          • RecordClone
          • RecordCopy
          • IRecordDelegates
        • FieldDelegates
          • FieldRead
          • FieldWrite
          • RecreateWith
          • IFieldDelegates
      • Reflection
        • EnumDescription
      • String
        • IEscaper
        • UnicodeString
        • Hex
      • Miscellaneous
        • IIdGenerator
        • Permutation
        • IReadOnly
        • IUserDataContainer
        • ITreeNode
        • Void
    • Avalanche.Writer
      • Introduction
      • ConstantWriter
      • Context
      • ConvertWriter
      • DefaultConstructor
      • DelegateWriter
      • PassthroughWriter
      • Referer
      • TypeCast
      • Writer
      • WriterPipe
      • WriterMessages

    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
    

    Cyclic query


    .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>
    
    In This Article
    Back to top Copyright © Toni Kalajainen