• 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

    IDataType

    IDataType is root interface for datatype descriptions. It carries no fields, but has some expected features.

    /// <summary>Datatype root interface</summary>
    public interface IDataType : IGraphComparable, IGraphEqualityComparable, ICloneable, IRecord, INominable, IDefaultValued<object?>
    {
        /// <summary>The interface type.</summary>
        [IgnoreDataMember] Type IntfType { get; set; }
        /// <summary>Component types</summary>
        [IgnoreDataMember] IDataType[] Components { get; }
        /// <summary>The container of this type is capable of holding unassigned state, also known as 'nullable', 'optional', and complement of 'required'.</summary>
        bool Unassignable { get; set; }
        /// <summary>Is instance of the type referable by identity.</summary>
        bool Referable { get; set; }
        /// <summary>Annotations. See <see cref="Annotation"/> for keys of wellknown annotations.</summary>
        IDictionary<string, string> Annotations { get; set; }
    
        /// <summary>Keys for wellknown keys for <see cref="Annotations"/>.</summary>
        public static class Annotation
        {
            /// <summary>Human readable description text about the type.</summary>
            public const string Description = nameof(Description);
            /// <summary>Human readable name of the type.</summary>
            public const string DisplayName = nameof(DisplayName);
        }
    }
    
    /// <summary>Contains Name property.</summary>
    public interface INominable
    {
        /// <summary>Object name</summary>
        IIdentity? Name { get; set; }
    }
    
    /// <summary>Contains default value property.</summary>
    public interface IDefaultValued<T>
    {
        /// <summary>Possible default value of <typeparamref name="T"/>.</summary>
        T DefaultValue { get; set; }
    }
    

    Avalanche.DataType introduces following basic datatypes:

    IDataType
    ├── IRecordType
    ├── IFieldType
    ├── IOneOfType
    ├── IListType
    │   └── IStringType
    ├── IValueType
    │   └── INumberType
    │       ├── IIntegerType
    │       │   └── IEnumerationType
    │       └── IRealType
    └── IAnyType
    

    Annotations

    Well-known annotations.

    Field Key Type Description
    IDataType.Annotation.Description Description string Human readable datatype description.
    IDataType.Annotation.DisplayName DisplayName string Human readable type name.

    Implementation

    IDataType base interface can be extended for third party types.

    public interface IMessageType : IDataType
    {
        IDataType Request { get; set; }
        IDataType Response { get; set; }
    }
    

    DataType is the class base for third party types.

    public class MessageType : DataType, IMessageType
    {
        /// <summary>Interface Type</summary>
        [IgnoreDataMember] public override Type IntfType { get => typeof(IMessageType); set => CoreMessages.Instance.BadReadOnly.Throw(); }
    
        [IgnoreDataMember] protected IDataType request = null!;
        [IgnoreDataMember] protected IDataType response = null!;
    
        public IDataType Request { get => request; set => this.AssertWritable().request = value; }
        public IDataType Response { get => response; set => this.AssertWritable().response = value; }
    
        /// <summary>Check validation.</summary>
        protected override void InternalValidate(ref StructList1<IMessage> errorCodes)
        {
            // Call base implementation
            base.InternalValidate(ref errorCodes);
            // Test properties
            if (Request == null) errorCodes.Add(DataTypeMessages.Instance.BadFieldNotFound.New(nameof(Request)));
            if (Response == null) errorCodes.Add(DataTypeMessages.Instance.BadFieldNotFound.New(nameof(Response)));
        }
    
    }
    

    Values are assignable with initializer.

    // Create message description
    IMessageType messageType = new MessageType
    {
        Name = Identities.CreateName("LookupMessage"),
        Description = "Table lookup message",
        Annotations = new LockableDictionary<string, string>(),
        DefaultValue = null,
        Unassignable = false,
        Referable = true,
        Request = DataTypes.String.Instance,
        Response = DataTypes.String.Instance
    }
    .SetReadOnly();
    

    And values are assignable with extension method setters.

    // Create message description
    IMessageType messageType = new MessageType
    {
        Request = DataTypes.String.Instance,
        Response = DataTypes.String.Instance
    }
    .SetName(Identities.CreateName("LookupMessage"))
    .SetDescription("Table lookup message")
    .SetAnnotations(new LockableDictionary<string, string>())
    .SetDefaultValue<MessageType, object?>(null)
    .SetUnassignable(false)
    .SetReferable(true)
    .SetReadOnly();
    

    Base class implements ICloneable and IGraphCloneable.

    MessageType clone = (MessageType)messageType.Clone();
    

    Extension method for IValidable asserts data type is valid.

    MessageType messageType = new MessageType();
    IMessage statusCode = messageType.ValidateSingle();
    WriteLine(statusCode); // "Request: Not found."
    

    Full Example

    Full example
    using System;
    using System.Runtime.Serialization;
    using Avalanche.Accessor;
    using Avalanche.DataType;
    using Avalanche.Identity;
    using Avalanche.Utilities;
    using Avalanche.Message;
    using static System.Console;
    
    public class datatype
    {
        public static void Run()
        {
            {
                // <01>
                // Create message description
                IMessageType messageType = new MessageType
                {
                    Name = Identities.CreateName("LookupMessage"),
                    Description = "Table lookup message",
                    Annotations = new LockableDictionary<string, string>(),
                    DefaultValue = null,
                    Unassignable = false,
                    Referable = true,
                    Request = DataTypes.String.Instance,
                    Response = DataTypes.String.Instance
                }
                .SetReadOnly();
                // </01>
            }
            {
                // <02>
                // Create message description
                IMessageType messageType = new MessageType
                {
                    Request = DataTypes.String.Instance,
                    Response = DataTypes.String.Instance
                }
                .SetName(Identities.CreateName("LookupMessage"))
                .SetDescription("Table lookup message")
                .SetAnnotations(new LockableDictionary<string, string>())
                .SetDefaultValue<MessageType, object?>(null)
                .SetUnassignable(false)
                .SetReferable(true)
                .SetReadOnly();
                // </02>
                // <03>
                MessageType clone = (MessageType)messageType.Clone();
                // </03>
            }
            {
                // <04>
                MessageType messageType = new MessageType();
                IMessage statusCode = messageType.ValidateSingle();
                WriteLine(statusCode); // "Request: Not found."
                // </04>
            }
        }
    
        // <200>
        public interface IMessageType : IDataType
        {
            IDataType Request { get; set; }
            IDataType Response { get; set; }
        }
        // </200>
    
        // <201>
        public class MessageType : DataType, IMessageType
        {
            /// <summary>Interface Type</summary>
            [IgnoreDataMember] public override Type IntfType { get => typeof(IMessageType); set => CoreMessages.Instance.BadReadOnly.Throw(); }
    
            [IgnoreDataMember] protected IDataType request = null!;
            [IgnoreDataMember] protected IDataType response = null!;
    
            public IDataType Request { get => request; set => this.AssertWritable().request = value; }
            public IDataType Response { get => response; set => this.AssertWritable().response = value; }
    
            /// <summary>Check validation.</summary>
            protected override void InternalValidate(ref StructList1<IMessage> errorCodes)
            {
                // Call base implementation
                base.InternalValidate(ref errorCodes);
                // Test properties
                if (Request == null) errorCodes.Add(DataTypeMessages.Instance.BadFieldNotFound.New(nameof(Request)));
                if (Response == null) errorCodes.Add(DataTypeMessages.Instance.BadFieldNotFound.New(nameof(Response)));
            }
    
        }
        // </201>
    }
    
    In This Article
    Back to top Copyright © Toni Kalajainen