• Avalanche
  • Avalanche.Core
  • Lexical

    Show / Hide Table of Contents
    • Avalanche.Localization
      • Introduction
      • Localization
      • LocalizationFile
      • LocalizationFiles
      • LocalizationFileSystem
      • LocalizationFileFormat
      • LocalizationLine
      • LocalizationLines
      • TemplateFormat
      • CultureProvider
      • FallbackCultureProvider
      • ResourceManager
      • LocalizationError
      • Microsoft.Extensions
        • Introduction
        • DependencyInjection
        • FileProvider
        • Logging
        • ITextLocalizer
        • IFileLocalizer
        • Localization
        • AspNetCore
      • Pluralization
        • Introduction
        • Multiple plural parameters
        • Custom PluralRules
        • Invariant Culture
        • Unit Prefix
        • IPluralRule
        • IPluralNumber
        • IPluralRules
        • CLDRs
        • Unicode.CLDR41
        • Unicode.CLDR40
      • Articles
        • Alphabet localization
        • Benchmarks
        • Caching
        • Class Library
        • Demo
        • Diagnostics
        • Embedded resources
        • Emplacement
        • File localization
        • Text localization
    • Avalanche.Message
      • Introduction
      • IMessage
      • IMessageProvider
      • IMessageDescription
      • IMessageDescriptions
      • MessageLevel
      • Message printing
      • Messages and Exceptions
      • Logging
      • Validation
      • Localization
    • Avalanche.StatusCode
      • Introduction
      • HResult
        • Introduction
        • HResult.Facilities
        • BasicMessages
        • RpcMessages
        • DispatchMessages
        • ItfMessages
        • Win32Messages
        • ClrMessages
      • 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
    • Avalanche.Template
      • Introduction
      • TemplateFormats
      • ITemplatePrintable
      • ITemplateFormatPrintable
      • ITemplateText
      • ITemplateBreakdown
      • ITemplateFormat
      • ITemplateFormats
      • Extract Arguments
      • Emplacement
    • Avalanche.Tokenizer
      • Introduction
      • IToken
      • ITokenizer
      • Tokenizers
    • Avalanche.Service
      • Introduction
      • Service
        • IService
        • Construction
        • Query
        • CancellationToken
        • CachePolicy
        • Cast
        • Scope
        • Dispose
      • Handler
        • Introduction
        • IHandler
        • Cancel
        • Recursion
        • Cyclicity
        • Delegates
        • Casting
        • Invokable
        • Handlers
      • Request
        • Introduction
        • IRequest
        • [Request]
        • [ContextParameter]
        • Print Tree
      • Dependency Injection
        • Introduction
        • ServiceRequest<T>
        • Handler
        • CachePolicy
        • CancellationToken
        • QueryLogger
      • Examples
        • Expression Example
        • Mapper Example
      • ServiceMessages
    • Avalanche.Writer
      • Introduction
      • Writer
      • Referer
      • TypeCast
      • DefaultConstructor
      • DelegateWriter
      • WriterPipe
      • ConstantWriter
      • PassthroughWriter
      • Context
      • WriterMessages
    • Avalanche.Accessor
      • Introduction
      • AccessorServices
      • List
        • ListAccessor
        • ListConstructor
        • ListDeconstructor
        • ListDefaultConstructor
        • ListGet
        • ListSet
        • ListAdd
        • ListInsert
        • ListClear
        • ListCount
        • ListIndexOf
        • ListRemoveAt
        • ListReferer
      • Map
        • MapAccessor
        • MapConstructor
        • MapDeconstructor
        • MapDefaultConstructor
        • MapSet
        • MapGet
        • MapRemove
        • MapClear
        • MapCount
        • MapReferer
      • Record
        • RecordAccessor
        • RecordConstructor
        • RecordDeconstructor
        • RecordDefaultConstructor
      • Field
        • FieldAccessor
        • FieldReader
        • FieldWriter
        • FieldReferer
      • Dependency Injection
        • Introduction
      • AccessorMessages
    • Avalanche.Emit
      • Introduction
      • TypeBuilder
      • ConstructorBuilder
      • MethodBuilder
      • PropertyBuilder
      • FieldBuilder
      • Emit
      • Utilities
    • Avalanche.DataType
      • Introduction
      • IDataTypeBase
      • IDataType
      • IRecordType
      • IFieldType
      • IUnionType
      • IListType
      • IMapType
      • IValueType
      • IEnumerationType
      • IIntegerType
      • IRealType
      • IStringType
      • IAnyType
      • DataTypeRequest
      • PrintTree
      • DataTypeMessages
    • 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
    • Avalanche.Identity
      • Introduction
      • Identity
      • IdentityParts
      • IdentityInterner
      • IdentityComparer
      • Print Tree
      • IdentityAccessors
        • Introduction
        • TypeName
    • 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
        • EnumerableCloner
        • FieldCloner
        • PassthroughCloner
        • RecordCloner
        • ClonerProvider
      • Dispose
        • IDisposeAttachable
        • IDisposeBelatable
      • Provider
        • Introduction
        • ProviderBase
        • Delegate
        • Concatenation
        • Cache
        • ResultCapture
        • AsReadOnly
        • AsService
      • Record
        • IRecordDescription
        • IFieldDescription
        • IConstructorDescription
        • IConstructionDescription
        • IParameterDescription
        • IRecordProviders
        • RecordDelegates
          • RecordCreate
          • RecordClone
          • RecordCopy
          • IRecordDelegates
        • FieldDelegates
          • FieldRead
          • FieldWrite
          • RecreateWith
          • IFieldDelegates
      • String
        • IEscaper
        • UnicodeString
      • Miscellaneous
        • IIdGenerator
        • Permutation
        • IReadOnly
        • IUserDataContainer
        • Void
    • Avalanche.Core
      • License
      • Order

    TypeName

    IdentityAccessors.Default.TypeName handles complete assembly qualified type names.

    // Get identity accessor
    IIdentityAccessor<Type> identityAccessor = IdentityAccessors.Default.TypeName;
    // Construct identity
    IIdentity identity = identityAccessor.Create(typeof(string));
    

    IdentityAccessors.Default.TypeNameWithoutAssembly handles type names without assembly parts.

    // Get identity accessor
    IIdentityAccessor<Type> identityAccessor = IdentityAccessors.Default.TypeNameWithoutAssembly;
    

    Construction

    TypeName.Create() constructs IIdentity from an instance of the native type.

    // Construct identity
    IIdentity identity = IdentityAccessors.Default.TypeName.Create(typeof(string));
    
    "String" → "System" → "6.0.0.0" → "System.Private.CoreLib" → 7cec85d7bea7798e → "neutral"
    

    TypeNameWithoutAssembly.Create() constructs without libarary parts.

    // Construct identity
    IIdentity identity = IdentityAccessors.Default.TypeNameWithoutAssembly.Create(typeof(string));
    
    "String" → "System"
    

    Deconstruct deconstructs IIdentity back into native type.

    // Create id
    IIdentity id = Identities.CreateNamespace("System").AppendName("String").SetReadOnly();
    // Deconstruct identity parts into native value
    Type type = IdentityAccessors.Default.TypeName.Deconstruct(id);
    

    Print and Parse

    C# System.Type has three kinds of type names.

    .Name is a simple name part without namespace.

    // Get type
    Type type = typeof(System.String);
    // "String"
    string name = type.Name;
    

    .FullName is namespace+name without the assembly. This is context-dependent identity, library being the context.

    // "System.String"
    string fullname = type.FullName;
    

    .AssemblyQualifiedName is a complete name with libary, version and culture. This identity can be used context-free.

    // "System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"
    string assemblyqualifiedName = type.AssemblyQualifiedName!;
    

    IdentityAccessors.Default.TypeNameWithoutAssembly and IdentityAccessors.Default.TypeName parses from all of the string formats System.Type produces.

    //
    string typename = "System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e";
    // Parse assembly qualified type name
    IIdentity id1 = IdentityAccessors.Default.TypeName.MemoryAccessors.Parse(typename);
    // Parse full name type name
    IIdentity id2 = IdentityAccessors.Default.TypeNameWithoutAssembly.MemoryAccessors.Parse(typename);
    // "Name("String") → Namespace("System") → Version("6.0.0.0") → Library("System.Private.CoreLib") → PublicKeyToken(7cec85d7bea7798e) → Culture("neutral")"
    Console.WriteLine(id1);
    // "Name("String") → Namespace("System")"
    Console.WriteLine(id2);
    

    TypeName prints C# type system compatible strings.

    // Construct identity
    IIdentity identity = IdentityAccessors.Default.TypeName.Create(typeof(string));
    // "System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"
    string assemblyQualified = IdentityAccessors.Default.TypeName.MemoryAccessors.Print(identity);
    // "System.String"
    string fullname = IdentityAccessors.Default.TypeNameWithoutAssembly.MemoryAccessors.Print(identity);
    

    Arrays

    Arrays are represented as "Array" part where and with Int32 label for array rank.

    Type type = typeof(string[]);
    IIdentity id = IdentityAccessors.Default.TypeNameWithoutAssembly.Create(type);
    
    Array[1] → Name("String") → Namespace("System")
    

    Generic Parameters

    Generic type parameters are constructed as IIdentity.Components.

    //
    Type type = typeof(Dictionary<string, int>);
    // 
    IIdentity id = IdentityAccessors.Default.TypeNameWithoutAssembly.Create(type);
    
    Name("Dictionary`2") → Namespace("Generic") → Namespace("Collections") → Namespace("System")
    ├── [0] Name("String") → Namespace("System")
    └── [1] Name("Int32") → Namespace("System")
    

    Inner Type

    Inner types have multiple 'Name' parts. Generic type parameters are on the tailing 'Name' part.

    // Create type
    Type type = typeof(OuterPart<object>.InnerPart<int>);
    // Create identity
    IIdentity id = IdentityAccessors.Default.TypeNameWithoutAssembly.Create(type);
    // Print
    Console.WriteLine(id.PrintTree());
    
    public class OuterPart<T>
    {
        public class InnerPart<Y> { }
    }
    
    Name("InnerPart`1") → Name("OuterPart`1")
    ├── [0] Name("Object") → Namespace("System")
    └── [1] Name("Int32") → Namespace("System")
    

    Other

    Extension method .PrintTree() extends Type classes. This is used for verbose debug printing.

    string print = typeof(IList<int>).PrintTree(assemblyQualified: false);
    
    Name("IList`1") → Namespace("Generic") → Namespace("Collections") → Namespace("System")
    └── [0] Name("Int32") → Namespace("System")
    

    Full Example

    Full example
    using System;
    using System.Collections.Generic;
    using Avalanche.Accessor;
    using Avalanche.Identity;
    using Avalanche.Serialization;
    using Avalanche.Service;
    using Avalanche.Utilities;
    using Avalanche.Writer;
    
    class typename
    {
        public static void Run()
        {
            {
                // <02>
                // Get identity accessor
                IIdentityAccessor<Type> identityAccessor = IdentityAccessors.Default.TypeName;
                // Construct identity
                IIdentity identity = identityAccessor.Create(typeof(string));
                // </02>
            }
    
            {
                // <03>
                // Get identity accessor
                IIdentityAccessor<Type> identityAccessor = IdentityAccessors.Default.TypeNameWithoutAssembly;
                // </03>
            }
            {
                // <04>
                // Construct identity
                IIdentity identity = IdentityAccessors.Default.TypeName.Create(typeof(string));
                // </04>
                Console.WriteLine(identity.PrintTree(format: IdentityPrintTreeExtensions.PrintFormat.DefaultVeryShort));
            }
            {
                // <04B>
                // Construct identity
                IIdentity identity = IdentityAccessors.Default.TypeNameWithoutAssembly.Create(typeof(string));
                // </04B>
                Console.WriteLine(identity.PrintTree(format: IdentityPrintTreeExtensions.PrintFormat.DefaultVeryShort));
            }
            {
                // <05>
                // Create id
                IIdentity id = Identities.CreateNamespace("System").AppendName("String").SetReadOnly();
                // Deconstruct identity parts into native value
                Type type = IdentityAccessors.Default.TypeName.Deconstruct(id);
                // </05>
            }
    
            {
                // <08>
                string print = typeof(IList<int>).PrintTree(assemblyQualified: false);
                // </08>
                Console.WriteLine(print);
            }
    
            {
                // <10>
                //
                Type type = typeof(Dictionary<string, int>);
                // 
                IIdentity id = IdentityAccessors.Default.TypeNameWithoutAssembly.Create(type);
                // </10>
                //
                id.PrintTreeTo(Console.Out);
            }
            {
                // <11>
                // Create type
                Type type = typeof(OuterPart<object>.InnerPart<int>);
                // Create identity
                IIdentity id = IdentityAccessors.Default.TypeNameWithoutAssembly.Create(type);
                // Print
                Console.WriteLine(id.PrintTree());
                // </11>
            }
    
    
            {
                // <20>
                Type type = typeof(string[]);
                IIdentity id = IdentityAccessors.Default.TypeNameWithoutAssembly.Create(type);
                // </20>
                id.PrintTreeTo(Console.Out);
            }
    
            {
                // <31>
                // Get type
                Type type = typeof(System.String);
                // "String"
                string name = type.Name;
                // </31>
                Console.WriteLine(name);
    
                // <32>
                // "System.String"
                string fullname = type.FullName;
                // </32>
                Console.WriteLine(fullname);
    
                // <33>
                // "System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"
                string assemblyqualifiedName = type.AssemblyQualifiedName!;
                // </33>
                Console.WriteLine(assemblyqualifiedName);
            }
    
            {
                // <34>
                //
                string typename = "System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e";
                // Parse assembly qualified type name
                IIdentity id1 = IdentityAccessors.Default.TypeName.MemoryAccessors.Parse(typename);
                // Parse full name type name
                IIdentity id2 = IdentityAccessors.Default.TypeNameWithoutAssembly.MemoryAccessors.Parse(typename);
                // "Name("String") → Namespace("System") → Version("6.0.0.0") → Library("System.Private.CoreLib") → PublicKeyToken(7cec85d7bea7798e) → Culture("neutral")"
                Console.WriteLine(id1);
                // "Name("String") → Namespace("System")"
                Console.WriteLine(id2);
                // </34>
            }
    
    
            {
                // <35>
                // Construct identity
                IIdentity identity = IdentityAccessors.Default.TypeName.Create(typeof(string));
                // "System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"
                string assemblyQualified = IdentityAccessors.Default.TypeName.MemoryAccessors.Print(identity);
                // "System.String"
                string fullname = IdentityAccessors.Default.TypeNameWithoutAssembly.MemoryAccessors.Print(identity);
                // </35>
            }
    
        }
    }
    
    
    // <12>
    public class OuterPart<T>
    {
        public class InnerPart<Y> { }
    }
    // </12>
    
    
    Back to top Copyright © 2022 Toni Kalajainen, contact@avalanche.fi