• 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

    IMapAccessor

    IMapAccessor describes writers that access a map. Map can exist as class, struct, memory-span or stream.

    /// <summary>Map accessor</summary>
    public interface IMapAccessor : IAccessorBase, IDefaultConstructorAccessor, IConstructorAccessor, IDeconstructorAccessor
    {
        /// <summary></summary>
        Type MapType { get; set; }
        /// <summary></summary>
        Type KeyType { get; set; }
        /// <summary></summary>
        Type ValueType { get; set; }
    
        /// <summary>Get reference to value</summary>
        IWriterBase Referer { get; set; }
        /// <summary>Remove at key</summary>
        IWriterBase Remove { get; set; }
        /// <summary>Get value at key.</summary>
        IWriterBase Get { get; set; }
        /// <summary>Set value at key.</summary>
        IWriterBase Set { get; set; }
        /// <summary>Clear list.</summary>
        IWriterFrom<Avalanche.Void> Clear { get; set; }
        /// <summary>Count.</summary>
        IWriterTo<long> Count { get; set; }
    }
    

    IMapAccessor<M> and IMapAccessor<M, K, V> describes accessor for container type M, key K and value V.

    /// <summary>Indicates that is map accessor of specific types.</summary>
    public interface IMapAccessorT : IMapAccessor, IAccessorT, IDefaultConstructorAccessorT { }
    /// <summary>Indicates <typeparamref name="Map"/> type.</summary>
    public interface IMapAccessor<Map> : IMapAccessorT, IAccessor<Map>, IDefaultConstructorAccessor<Map>, IConstructorAccessor<Map>, IDeconstructorAccessor<Map> { }
    /// <summary>Indicates <typeparamref name="Key"/> type.</summary>
    public interface IMapAccessorKeyOf<Key> : IMapAccessorT { }
    /// <summary>Indicates <typeparamref name="Value"/> type.</summary>
    public interface IMapAccessorValueOf<Value> : IMapAccessorT { }
    
    /// <summary>Map accessor of <typeparamref name="Map"/>.</summary>
    public interface IMapAccessor<Map, Key, Value> : IMapAccessor<Map>, IMapAccessorKeyOf<Key>, IMapAccessorValueOf<Value>, IConstructorAccessor<Map, IEnumerable<KeyValuePair<Key, Value>>>, IDeconstructorAccessor<Map, IEnumerable<KeyValuePair<Key, Value>>>
    {
        /// <summary>Get reference to value</summary>
        new IWriterBase Referer { get; set; }
        /// <summary>Remove at key</summary>
        new IWriterBase<Key, Map> Remove { get; set; }
        /// <summary>Get value at key.</summary>
        new IWriterBase<(Map, Key), Value> Get { get; set; }
        /// <summary>Set value at key.</summary>
        new IWriterBase<(Key, Value), Map> Set { get; set; }
        /// <summary>Clear list.</summary>
        new IWriterBase<Avalanche.Void, Map> Clear { get; set; }
        /// <summary>Count.</summary>
        new IWriterBase<Map, long> Count { get; set; }
    }
    

    IMapVisitor and IMapVisitorT are visitor interfaces for IAccessorBase.Accept(IAccessorVisitor).

    /// <summary>Base interface for map visitor</summary>
    public interface IMapVisitor : IAccessorVisitor
    {
        /// <summary>Try visit <paramref name="mapAccessor"/>.</summary>
        /// <returns>true to continue visitation</returns>
        bool VisitMapAccessor(IMapAccessor mapAccessor);
    }
    
    /// <summary>Base interface for map visitor</summary>
    public interface IMapVisitorT : IAccessorVisitor
    {
        /// <summary>Try visit <paramref name="mapAccessor"/>.</summary>
        /// <returns>true to continue visitation</returns>
        bool VisitMapAccessor<Map, Key, Value>(IMapAccessor<Map, Key, Value> mapAccessor);
    }
    

    MapAccessor

    MapAccessor<M, K, V> is the default implementation.

    IMapAccessor<Dictionary<string, int>, string, int> mapAccessor = new MapAccessor<Dictionary<string, int>, string, int>()
    {
        Constructor = null!,
        Deconstructor = null!,
        DefaultConstructor = null!,
        Referer = null!,
        Remove = null!,
        Get = null!,
        Set = null!,
        Clear = null!,
        Count = null!
    }.SetReadOnly();
    

    MapAccessor.Create(Type, Type, Type) also constructs IMapAccessor<M, K, V>. There is a setter method for each field.

    IMapAccessor<Dictionary<string, int>, string, int> mapAccessor =
        (IMapAccessor<Dictionary<string, int>, string, int>)
        MapAccessor.Create(typeof(Dictionary<string, int>), typeof(string), typeof(int))
        .SetConstructor(null!)
        .SetDeconstructor(null!)
        .SetDefaultConstructor(null!)
        .SetReferer(null!)
        .SetRemove(null!)
        .SetGet(null!)
        .SetSet(null!)
        .SetClear(null!)
        .SetCount(null!)
        .SetReadOnly();
    

    MapAccessorRequest

    MapAccessorRequest.Create(Type) creates a request for implementation to IMapAccessor<M>.

    // Create request
    MapAccessorRequest request = MapAccessorRequest.Create(typeof(Dictionary<string, int>));
    // Issue request
    IMapAccessor<Dictionary<string, int>, string, int> accessor =
        AccessorServices.Instance
        .GetRequired<MapAccessorRequest, IMapAccessor<Dictionary<string, int>, string, int>>(request);
    

    IService.GetMapAccessor<M>() extension method creates and executes MapAccessorRequest.

    IMapAccessor<Dictionary<string, int>> accessor =
        AccessorServices.Instance
        .GetMapAccessor<Dictionary<string, int>>();
    

    If dependency injection is used, MapAccessorRequest can be issued with service request to IMapAccessor<M>.

    IMapAccessor<Dictionary<string, int>> accessor =
        AccessorServices.Instance
        .GetRequiredService<IMapAccessor<Dictionary<string, int>>>();
    

    Usage

    .DefaultConstructor is a writer that creates map with default value.

    Dictionary<string, int> map = accessor.DefaultConstructor.Read();
    

    .Constructor is a writer that creates map from enumerable.

    KeyValuePair<string, int>[] data = new[] { new KeyValuePair<string, int>("Hello", 753) };
    Dictionary<string, int> map = accessor
        .Constructor
        .ReadAs<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>>(data);
    

    .Deconstructor is a writer that reads values as a enumerable.

    IEnumerable<KeyValuePair<string, int>> deconstruction =
        accessor
        .Deconstructor
        .ReadAs<Dictionary<string, int>, IEnumerable<KeyValuePair<string, int>>>(myMap);
    

    .Set is writer that assigns an element.

    IMapAccessor<Dictionary<string, int>, string, int> accessor =
        AccessorServices.Instance
        .GetRequiredService<IMapAccessor<Dictionary<string, int>, string, int>>();
    Dictionary<string, int> map = new Dictionary<string, int>();
    accessor.Set.Write(("ABC", 123), map);
    

    Full Example

    Full example
    using System.Collections.Generic;
    using Avalanche.Accessor;
    using Avalanche.Service;
    using Avalanche.Utilities;
    using Avalanche.Writer;
    using Microsoft.Extensions.DependencyInjection;
    
    public class mapaccessor
    {
        public static void Run()
        {
            {
                // <01>
                IMapAccessor<Dictionary<string, int>, string, int> mapAccessor = new MapAccessor<Dictionary<string, int>, string, int>()
                {
                    Constructor = null!,
                    Deconstructor = null!,
                    DefaultConstructor = null!,
                    Referer = null!,
                    Remove = null!,
                    Get = null!,
                    Set = null!,
                    Clear = null!,
                    Count = null!
                }.SetReadOnly();
                // </01>
            }
            {
                // <02>
                IMapAccessor<Dictionary<string, int>, string, int> mapAccessor =
                    (IMapAccessor<Dictionary<string, int>, string, int>)
                    MapAccessor.Create(typeof(Dictionary<string, int>), typeof(string), typeof(int))
                    .SetConstructor(null!)
                    .SetDeconstructor(null!)
                    .SetDefaultConstructor(null!)
                    .SetReferer(null!)
                    .SetRemove(null!)
                    .SetGet(null!)
                    .SetSet(null!)
                    .SetClear(null!)
                    .SetCount(null!)
                    .SetReadOnly();
                // </02>
            }
    
            {
                // <11>
                // Create request
                MapAccessorRequest request = MapAccessorRequest.Create(typeof(Dictionary<string, int>));
                // Issue request
                IMapAccessor<Dictionary<string, int>, string, int> accessor =
                    AccessorServices.Instance
                    .GetRequired<MapAccessorRequest, IMapAccessor<Dictionary<string, int>, string, int>>(request);
                // </11>
            }
            {
                // <13>
                IMapAccessor<Dictionary<string, int>> accessor =
                    AccessorServices.Instance
                    .GetMapAccessor<Dictionary<string, int>>();
                // </13>
            }
            {
                // <14>
                IMapAccessor<Dictionary<string, int>> accessor =
                    AccessorServices.Instance
                    .GetRequiredService<IMapAccessor<Dictionary<string, int>>>();
                // </14>
            }
    
            {
                IMapAccessor<Dictionary<string, int>> accessor = AccessorServices.Instance.GetRequiredService<IMapAccessor<Dictionary<string, int>>>();
                // <21>
                Dictionary<string, int> map = accessor.DefaultConstructor.Read();
                // </21>
            }
            {
                IMapAccessor<Dictionary<string, int>> accessor = AccessorServices.Instance.GetRequiredService<IMapAccessor<Dictionary<string, int>>>();
                // <22>
                KeyValuePair<string, int>[] data = new[] { new KeyValuePair<string, int>("Hello", 753) };
                Dictionary<string, int> map = accessor
                    .Constructor
                    .ReadAs<IEnumerable<KeyValuePair<string, int>>, Dictionary<string, int>>(data);
                // </22>
            }
            {
                IMapAccessor<Dictionary<string, int>> accessor =
                    AccessorServices.Instance
                    .GetRequiredService<IMapAccessor<Dictionary<string, int>>>();
                Dictionary<string, int> myMap = new Dictionary<string, int> { { "World", 444 } };
                // <23>
                IEnumerable<KeyValuePair<string, int>> deconstruction =
                    accessor
                    .Deconstructor
                    .ReadAs<Dictionary<string, int>, IEnumerable<KeyValuePair<string, int>>>(myMap);
                // </23>
            }
            {
                // <24>
                IMapAccessor<Dictionary<string, int>, string, int> accessor =
                    AccessorServices.Instance
                    .GetRequiredService<IMapAccessor<Dictionary<string, int>, string, int>>();
                Dictionary<string, int> map = new Dictionary<string, int>();
                accessor.Set.Write(("ABC", 123), map);
                // </24>
            }
    
        }
    }
    
    Back to top Copyright © 2022 Toni Kalajainen, contact@avalanche.fi