• 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

    IConstructionDescription

    IConstructionDescription description of how to apply source values on IConstructorDescription and fields.

    /// <summary>Description of how to apply <see cref="IConstructorDescription"/>, a constructor-parameter-to-field correlaton.</summary>
    public interface IConstructionDescription
    {
        /// <summary>Constructor to match</summary>
        IConstructorDescription Constructor { get; set; }
        /// <summary>Parameters to match to</summary>
        IParameterDescription[] Parameters { get; set; }
        /// <summary>Fields to match to</summary>
        IFieldDescription[] Fields { get; set; }
    
        /// <summary>Constructor Parameter to Record Field correlations</summary>
        IDictionary<IParameterDescription, IFieldDescription> ParameterToField { get; set; }
        /// <summary>Record Field to Constructo Parameter</summary>
        IDictionary<IFieldDescription, IParameterDescription> FieldToParameter { get; set; }
    
        /// <summary>Unmatched constructor parameters</summary>
        IList<IParameterDescription> UnmatchedParameters { get; set; }
        /// <summary>Unmatched constructor fields</summary>
        IList<IFieldDescription> UnmatchedFields { get; set; }
    }
    

    ConstructionDescriptor is the default implementation.

    IConstructionDescription constructionDescription = new ConstructionDescription()
    {
        Constructor = null!,
        Parameters = new IParameterDescription[0],
        Fields = new IFieldDescription[0],
        ParameterToField = null!,
        FieldToParameter = null!,
        UnmatchedParameters = new IParameterDescription[0],
        UnmatchedFields = new IFieldDescription[0]
    }.SetReadOnly();
    

    Extension methods can be used to set each field.

    IConstructionDescription constructionDescription =
        new ConstructionDescription()
        .SetConstructor(null!)
        .SetParameters(new IParameterDescription[0])
        .SetFields(new IFieldDescription[0])
        .SetUnmatchedParameters(new IParameterDescription[0])
        .SetUnmatchedFields(new IFieldDescription[0])
        .SetReadOnly();
    

    .Clone() makes a copy.

    IConstructionDescription clone = constructionDescription.Clone().SetReadOnly();
    

    .CreateConstructionDescription() converts IConstructorDescription to construction description.

    // Create delegate ctor
    Func<int, MyClass> ctor = (int value) => new MyClass(value);
    //
    IRecordDescription recordDescription = new RecordDescription().Read(typeof(MyClass));
    // Create constructor description from delegate
    IConstructorDescription constructorDescription = new ConstructorDescription().SetRecord(recordDescription).Read(ctor);
    // Create construction description
    IConstructionDescription constructionDescription = constructorDescription.CreateConstructionDescription();
    

    .Score() creates comparable heuristic on applicability of constructor.

    int score = constructionDescription.Score();
    
    public class MyClass
    {
        public readonly int value;
    
        public MyClass(int value)
        {
            this.value = value;
        }
    }
    

    Full Example

    Full example
    using System;
    using Avalanche.Utilities;
    using Avalanche.Utilities.Record;
    
    class constructiondescription
    {
        public static void Run()
        {
            {
                // <01>
                IConstructionDescription constructionDescription = new ConstructionDescription()
                {
                    Constructor = null!,
                    Parameters = new IParameterDescription[0],
                    Fields = new IFieldDescription[0],
                    ParameterToField = null!,
                    FieldToParameter = null!,
                    UnmatchedParameters = new IParameterDescription[0],
                    UnmatchedFields = new IFieldDescription[0]
                }.SetReadOnly();
                // </01>
            }
            {
                // <02>
                IConstructionDescription constructionDescription =
                    new ConstructionDescription()
                    .SetConstructor(null!)
                    .SetParameters(new IParameterDescription[0])
                    .SetFields(new IFieldDescription[0])
                    .SetUnmatchedParameters(new IParameterDescription[0])
                    .SetUnmatchedFields(new IFieldDescription[0])
                    .SetReadOnly();
                // </02>
                // <03>
                IConstructionDescription clone = constructionDescription.Clone().SetReadOnly();
                // </03>
            }
            {
                // <04>
                // Create delegate ctor
                Func<int, MyClass> ctor = (int value) => new MyClass(value);
                //
                IRecordDescription recordDescription = new RecordDescription().Read(typeof(MyClass));
                // Create constructor description from delegate
                IConstructorDescription constructorDescription = new ConstructorDescription().SetRecord(recordDescription).Read(ctor);
                // Create construction description
                IConstructionDescription constructionDescription = constructorDescription.CreateConstructionDescription();
                // </04>
                // <05>
                int score = constructionDescription.Score();
                // </05>
            }
        }
    
        // <06>
        public class MyClass
        {
            public readonly int value;
    
            public MyClass(int value)
            {
                this.value = value;
            }
        }
        // </06>
    
    }
    
    In This Article
    Back to top Copyright © Toni Kalajainen