• 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.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
    • 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.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
      • Examples
        • NodeCount
        • Expression
        • Mapper
      • Articles
        • Benchmarks
        • Error Handling
        • ServiceMessages
    • 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
      • 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
      • String
        • IEscaper
        • UnicodeString
      • Miscellaneous
        • IIdGenerator
        • Permutation
        • IReadOnly
        • IUserDataContainer
        • Void
    • Avalanche.Writer
      • Introduction
      • ConstantWriter
      • Context
      • ConvertWriter
      • DefaultConstructor
      • DelegateWriter
      • PassthroughWriter
      • Referer
      • TypeCast
      • Writer
      • WriterPipe
      • WriterMessages

    ITemplateFormats

    ITemplateFormats is a table that manages ITemplateFormats.

    /// <summary>Configurable table of template formats.</summary>
    public interface ITemplateFormats
    {
        /// <summary>List of all formats, excluding detect format</summary>
        ITemplateFormat[] AllFormats { get; set; }
        /// <summary>Format by name, including <see cref="Detect"/>.</summary>
        IProvider<string, ITemplateFormat> ByName { get; set; }
        /// <summary>Auto-detect format</summary>
        ITemplateFormat Detect { get; set; }
    }
    

    TemplateFormatsBase is simple implementation where each property must be manually assigned.

    // Create template formats table
    TemplateFormatsBase templateFormats = new TemplateFormatsBase();
    // Assign all
    templateFormats.AllFormats = new ITemplateFormat[] { BraceTemplateFormat.AlphaNumeric, BraceTemplateFormat.Numeric };
    templateFormats.Detect = new DetectTemplateFormat("Detect", templateFormats.AllFormats);
    templateFormats.ByName = TemplateFormatsBase.CreateByNameProvider(templateFormats).Cached();
    // Make immutable
    templateFormats.SetReadOnly();
    

    TemplateFormats is easier-to-use implementation where .AllFormats is the only property that needs to be assigned. AllFormats can be reassigned later, provided it's not in read-only state. Formats can be assigned at construction. .ByName and .Detect are automatically created, cannot be setted, and getter always return the same object references, which are automatically kept up-to-date.

    ITemplateFormats templateFormats = new TemplateFormats(BraceTemplateFormat.AlphaNumeric, BraceTemplateFormat.Numeric).SetReadOnly();
    

    TemplateFormats.Add(templateformat) adds a format thread-safely.

    TemplateFormats templateFormats = new TemplateFormats()
        .Add(BraceTemplateFormat.AlphaNumeric)
        .Add(BraceTemplateFormat.Numeric)
        .SetReadOnly();
    

    .ByName returns format by its name.

    ITemplateFormat templateFormat = templateFormats.ByName["BraceNumeric"];
    

    .Detect is template format that detects best matching format.

    // Create format table
    ITemplateFormats templateFormats = new TemplateFormats(BraceTemplateFormat.AlphaNumeric, BraceTemplateFormat.Numeric).SetReadOnly();
    // Parse template into breakdown
    ITemplateBreakdown templateText = templateFormats.Detect.Breakdown["Hello {user}, welcome to {location}."];
    

    Full Example

    Full example
    using System.Collections.Concurrent;
    using Avalanche.Template;
    using Avalanche.Utilities;
    using Avalanche.Utilities.Provider;
    
    public class itemplateformats
    {
        public static void Run()
        {
            {
                // <01>
                // Create template formats table
                TemplateFormatsBase templateFormats = new TemplateFormatsBase();
                // Assign all
                templateFormats.AllFormats = new ITemplateFormat[] { BraceTemplateFormat.AlphaNumeric, BraceTemplateFormat.Numeric };
                templateFormats.Detect = new DetectTemplateFormat("Detect", templateFormats.AllFormats);
                templateFormats.ByName = TemplateFormatsBase.CreateByNameProvider(templateFormats).Cached();
                // Make immutable
                templateFormats.SetReadOnly();
                // </01>
                var format = templateFormats.ByName["Detect"];
                format = templateFormats.ByName["BraceNumeric"];
            }
            {
                // <02>
                ITemplateFormats templateFormats = new TemplateFormats(BraceTemplateFormat.AlphaNumeric, BraceTemplateFormat.Numeric).SetReadOnly();
                // </02>
                var format = templateFormats.ByName["Detect"];
            }
            {
                // <03>
                TemplateFormats templateFormats = new TemplateFormats()
                    .Add(BraceTemplateFormat.AlphaNumeric)
                    .Add(BraceTemplateFormat.Numeric)
                    .SetReadOnly();
                // </03>
                var format = templateFormats.ByName["Detect"];
            }
            {
                ITemplateFormats templateFormats = new TemplateFormats(BraceTemplateFormat.AlphaNumeric, BraceTemplateFormat.Numeric).SetReadOnly();
                // <11>
                ITemplateFormat templateFormat = templateFormats.ByName["BraceNumeric"];
                // </11>
                var format = templateFormats.ByName["Detect"];
            }
            {
                // <12>
                // Create format table
                ITemplateFormats templateFormats = new TemplateFormats(BraceTemplateFormat.AlphaNumeric, BraceTemplateFormat.Numeric).SetReadOnly();
                // Parse template into breakdown
                ITemplateBreakdown templateText = templateFormats.Detect.Breakdown["Hello {user}, welcome to {location}."];
                // </12>
                var format = templateFormats.ByName["Detect"];
            }
        }
    }
    
    
    In This Article
    Back to top Copyright © Toni Kalajainen