• 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

    EnumConverter

    EnumConverter.TryGet(fromType, toType, out writer) tries to get enum converter.

    bool ok = EnumConverter.TryGet(typeof(Country), typeof(string), out IWriter converter);
    string value = converter.ReadAs<Country, string>(Country.Finland);
    

    EnumConverter.EnumBoxToInteger<E, I> converts enum type to integer type as Enum envelope type (and also object).

    IWriterToRef<Enum, ulong> converter = EnumConverter.EnumBoxToInteger<Country, ulong>.Instance;
    ulong value = converter.Read(Country.Finland);
    
    [Flags]
    public enum Countries
    {
        Finland = 1,
        Sweden = 2,
        Norway = 4
    }
    
    public enum Country
    {
        Finland = 1,
        Sweden = 2,
        Norway = 3
    }
    

    EnumConverter.IntegerToEnumBox<E, I> converts integer type to enum type as Enum envelope type (and also object).

    IWriterToRef<ulong, Enum> converter = EnumConverter.IntegerToEnumBox<Country, ulong>.Instance;
    Enum @enum = converter.Read(1UL);
    

    EnumConverter.EnumValueToInteger<E, I> converts enum value to integer type.

    IWriterToRef<Country, ulong> converter = EnumConverter.EnumValueToInteger<Country, ulong>.Instance;
    ulong value = converter.Read(Country.Finland);
    

    EnumConverter.IntegerToEnumValue<E, I> converts integer type to enum value.

    IWriterToRef<ulong, Country> converter = EnumConverter.IntegerToEnumValue<Country, ulong>.Instance;
    Country country = converter.Read(1UL);
    

    EnumConverter.CreateEnumToEnumConverter is enum-to-enum converter. Conversion is matched by item name.

    IEnumDescription countryEnumDescription = EnumDescription.CreateForEnumType(typeof(Country));
    IEnumDescription countriesEnumDescription = EnumDescription.CreateForEnumType(typeof(Countries));
    IWriterToRef<Country, Countries> converter = (IWriterToRef<Country, Countries>)EnumConverter.CreateEnumToEnumConverter(countryEnumDescription, countriesEnumDescription);
    Countries countries = converter.Read(Country.Finland);
    

    .CreateEnumToName() creates converter that converts enum to name.

    IWriterToRef<Country, string> converter = (IWriterToRef<Country, string>)EnumDescription.CreateForEnumType(typeof(Country)).CreateEnumToName();
    string name = converter.Read(Country.Finland);
    

    .CreateEnumToNames() creates converter that converts enum flags to names.

    IWriterToRef<Countries, string[]> converter = (IWriterToRef<Countries, string[]>)EnumDescription.CreateForEnumType(typeof(Countries)).CreateEnumToNames();
    string[] names = converter.Read(Countries.Finland | Countries.Sweden);
    

    .CreateNameToEnum() converts name to enum value.

    IWriterToRef<string, Country> converter = (IWriterToRef<string, Country>)EnumDescription.CreateForEnumType(typeof(Country)).CreateNameToEnum();
    Country country = converter.Read("Finland");
    

    .CreateNamesToEnum() converts names to enum flags.

    IWriterToRef<string[], Countries> converter = (IWriterToRef<string[], Countries>)EnumDescription.CreateForEnumType(typeof(Countries)).CreateNamesToEnum();
    Countries countries = converter.Read(new string[] { "Finland", "Sweden" });
    

    There are try-creates for various enum converters.

    EnumConverter.TryCreateEnumBoxToInteger(typeof(Country), typeof(byte), out EnumConverter.IEnumWriter? writer1);
    EnumConverter.TryCreateEnumBoxToInteger(typeof(Countries), typeof(sbyte), out EnumConverter.IEnumWriter? writer2);
    EnumConverter.TryCreateEnumValueToInteger(typeof(Country), typeof(short), out EnumConverter.IEnumWriter? writer3);
    EnumConverter.TryCreateEnumValueToInteger(typeof(Countries), typeof(ushort), out EnumConverter.IEnumWriter? writer4);
    EnumConverter.TryCreateIntegerToEnumBox(typeof(Country), typeof(byte), out EnumConverter.IEnumWriter? writer5);
    EnumConverter.TryCreateIntegerToEnumBox(typeof(Countries), typeof(sbyte), out EnumConverter.IEnumWriter? writer6);
    EnumConverter.TryCreateIntegerToEnumValue(typeof(Country), typeof(short), out EnumConverter.IEnumWriter? writer7);
    EnumConverter.TryCreateIntegerToEnumValue(typeof(Countries), typeof(ushort), out EnumConverter.IEnumWriter? writer8);
    

    .CreateEnumToIndex() creates converter that converts enum to index.

    IWriterToRef<Country, int> converter = (IWriterToRef<Country, int>)EnumDescription.Cached[typeof(Country)].CreateEnumToIndex();
    int index = converter.Read(Country.Finland);
    

    .CreateEnumToIndices() creates converter that converts enum flags to indices.

    IWriterToRef<Countries, int[]> converter = (IWriterToRef<Countries, int[]>)EnumDescription.Cached[typeof(Countries)].CreateEnumToIndices();
    int[] indices = converter.Read(Countries.Finland | Countries.Sweden);
    

    .CreateIndexToEnum() converts index to enum value.

    IWriterToRef<int, Country> converter = (IWriterToRef<int, Country>)EnumDescription.Cached[typeof(Country)].CreateIndexToEnum();
    Country country = converter.Read(0);
    

    .CreateIndicesToEnum() converts indices to enum flags.

    IWriterToRef<int[], Countries> converter = (IWriterToRef<int[], Countries>)EnumDescription.Cached[typeof(Countries)].CreateIndicesToEnum();
    Countries countries = converter.Read(new int[] { 0, 1 });
    

    [EnumOf] attribute is also conversible with enum types.

    // Get [EnumOf]
    EnumOfAttribute languageEnumOf = typeof(MyRecord200)
        .GetProperty(nameof(MyRecord200.Languages))!
        .GetCustomAttribute<EnumOfAttribute>()!;
    // Create IEnumDescription
    IEnumDescription languageEnumDescription = EnumDescription.CreateForEnumOf(languageEnumOf, null);
    IEnumDescription language2EnumDescription = EnumDescription.CreateForEnumType(typeof(Language2));
    // 
    IWriterToRef<string, Language2> converter = (IWriterToRef<string, Language2>)EnumConverter.CreateEnumToEnumConverter(languageEnumDescription, language2EnumDescription);
    // Convert
    Language2 language = converter.Read("Finnish");
    
    public record MyRecord200
    {
        [EnumOf<string, Languages>(isFlags: true)]
        public string Languages { get; set; } = "Finnish";
    }
    
    public class Languages : IEnumerable<IEnumItem<object>>
    {
        IEnumItem<object>[] content = new IEnumItem<object>[] {
            new EnumItem("Languages:Finnish", "Finnish", "Finnish", "Finnish"),
            new EnumItem("Languages:Swedish", "Swedish", "Swedish", "Swedish"),
            new EnumItem("Languages:Norwegian", "Norwegian", "Norwegian", "Norwegian"),
        };
    
        public IEnumerator<IEnumItem<object>> GetEnumerator() => ((IEnumerable<IEnumItem<object>>)content).GetEnumerator();
        IEnumerator IEnumerable.GetEnumerator() => content.GetEnumerator();
    }
    
    [Flags]
    public enum Language2
    {
        Finnish = 1 << 0,
        Swedish = 1 << 1,
        Norwegian = 1 << 2
    }
    

    Enum converters can be requested with ConverterRequest.

    // Create service stack
    IService service = Services.Create(ConverterHandlers.Instance);
    // Create enum descriptions
    IEnumDescription countryEnumDescription = EnumDescription.CreateForEnumType(typeof(Country));
    IEnumDescription countriesEnumDescription = EnumDescription.CreateForEnumType(typeof(Countries));
    // Create converter request
    ConverterRequest converterRequest = new ConverterRequest(countryEnumDescription, countriesEnumDescription);
    // Query converter
    IWriterToRef<Country, Countries> converter = service.GetRequired<ConverterRequest, IWriterToRef<Country, Countries>>(converterRequest);
    // Convert
    Countries countries = converter.Read(Country.Finland);
    

    Full Example

    Full example
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Reflection;
    using Avalanche.Converter;
    using Avalanche.Service;
    using Avalanche.Utilities;
    using Avalanche.Writer;
    
    public class enumconverter
    {
        public static void Run()
        {
            {
                // <00>
                bool ok = EnumConverter.TryGet(typeof(Country), typeof(string), out IWriter converter);
                string value = converter.ReadAs<Country, string>(Country.Finland);
                // </00>
            }
            {
                // <01>
                IWriterToRef<Enum, ulong> converter = EnumConverter.EnumBoxToInteger<Country, ulong>.Instance;
                ulong value = converter.Read(Country.Finland);
                // </01>
            }
            {
                // <02>
                IWriterToRef<ulong, Enum> converter = EnumConverter.IntegerToEnumBox<Country, ulong>.Instance;
                Enum @enum = converter.Read(1UL);
                // </02>
            }
            {
                // <03>
                IWriterToRef<Country, ulong> converter = EnumConverter.EnumValueToInteger<Country, ulong>.Instance;
                ulong value = converter.Read(Country.Finland);
                // </03>
            }
            {
                // <04>
                IWriterToRef<ulong, Country> converter = EnumConverter.IntegerToEnumValue<Country, ulong>.Instance;
                Country country = converter.Read(1UL);
                // </04>
            }
            {
                // <05>
                IEnumDescription countryEnumDescription = EnumDescription.CreateForEnumType(typeof(Country));
                IEnumDescription countriesEnumDescription = EnumDescription.CreateForEnumType(typeof(Countries));
                IWriterToRef<Country, Countries> converter = (IWriterToRef<Country, Countries>)EnumConverter.CreateEnumToEnumConverter(countryEnumDescription, countriesEnumDescription);
                Countries countries = converter.Read(Country.Finland);
                // </05>
            }
            {
                // <06>
                IWriterToRef<Country, string> converter = (IWriterToRef<Country, string>)EnumDescription.CreateForEnumType(typeof(Country)).CreateEnumToName();
                string name = converter.Read(Country.Finland);
                // </06>
            }
            {
                // <07>
                IWriterToRef<Countries, string[]> converter = (IWriterToRef<Countries, string[]>)EnumDescription.CreateForEnumType(typeof(Countries)).CreateEnumToNames();
                string[] names = converter.Read(Countries.Finland | Countries.Sweden);
                // </07>
            }
            {
                // <08>
                IWriterToRef<string, Country> converter = (IWriterToRef<string, Country>)EnumDescription.CreateForEnumType(typeof(Country)).CreateNameToEnum();
                Country country = converter.Read("Finland");
                // </08>
            }
            {
                // <09>
                IWriterToRef<string[], Countries> converter = (IWriterToRef<string[], Countries>)EnumDescription.CreateForEnumType(typeof(Countries)).CreateNamesToEnum();
                Countries countries = converter.Read(new string[] { "Finland", "Sweden" });
                // </09>
            }
            {
                // <10>
                EnumConverter.TryCreateEnumBoxToInteger(typeof(Country), typeof(byte), out EnumConverter.IEnumWriter? writer1);
                EnumConverter.TryCreateEnumBoxToInteger(typeof(Countries), typeof(sbyte), out EnumConverter.IEnumWriter? writer2);
                EnumConverter.TryCreateEnumValueToInteger(typeof(Country), typeof(short), out EnumConverter.IEnumWriter? writer3);
                EnumConverter.TryCreateEnumValueToInteger(typeof(Countries), typeof(ushort), out EnumConverter.IEnumWriter? writer4);
                EnumConverter.TryCreateIntegerToEnumBox(typeof(Country), typeof(byte), out EnumConverter.IEnumWriter? writer5);
                EnumConverter.TryCreateIntegerToEnumBox(typeof(Countries), typeof(sbyte), out EnumConverter.IEnumWriter? writer6);
                EnumConverter.TryCreateIntegerToEnumValue(typeof(Country), typeof(short), out EnumConverter.IEnumWriter? writer7);
                EnumConverter.TryCreateIntegerToEnumValue(typeof(Countries), typeof(ushort), out EnumConverter.IEnumWriter? writer8);
                // </10>
            }
    
            {
                // <16>
                IWriterToRef<Country, int> converter = (IWriterToRef<Country, int>)EnumDescription.Cached[typeof(Country)].CreateEnumToIndex();
                int index = converter.Read(Country.Finland);
                // </16>
            }
            {
                // <17>
                IWriterToRef<Countries, int[]> converter = (IWriterToRef<Countries, int[]>)EnumDescription.Cached[typeof(Countries)].CreateEnumToIndices();
                int[] indices = converter.Read(Countries.Finland | Countries.Sweden);
                // </17>
            }
            {
                // <18>
                IWriterToRef<int, Country> converter = (IWriterToRef<int, Country>)EnumDescription.Cached[typeof(Country)].CreateIndexToEnum();
                Country country = converter.Read(0);
                // </18>
            }
            {
                // <19>
                IWriterToRef<int[], Countries> converter = (IWriterToRef<int[], Countries>)EnumDescription.Cached[typeof(Countries)].CreateIndicesToEnum();
                Countries countries = converter.Read(new int[] { 0, 1 });
                // </19>
            }
    
            {
                // <20>
                // Get [EnumOf]
                EnumOfAttribute languageEnumOf = typeof(MyRecord200)
                    .GetProperty(nameof(MyRecord200.Languages))!
                    .GetCustomAttribute<EnumOfAttribute>()!;
                // Create IEnumDescription
                IEnumDescription languageEnumDescription = EnumDescription.CreateForEnumOf(languageEnumOf, null);
                IEnumDescription language2EnumDescription = EnumDescription.CreateForEnumType(typeof(Language2));
                // 
                IWriterToRef<string, Language2> converter = (IWriterToRef<string, Language2>)EnumConverter.CreateEnumToEnumConverter(languageEnumDescription, language2EnumDescription);
                // Convert
                Language2 language = converter.Read("Finnish");
                // </20>
            }
            {
                // <30>
                // Create service stack
                IService service = Services.Create(ConverterHandlers.Instance);
                // Create enum descriptions
                IEnumDescription countryEnumDescription = EnumDescription.CreateForEnumType(typeof(Country));
                IEnumDescription countriesEnumDescription = EnumDescription.CreateForEnumType(typeof(Countries));
                // Create converter request
                ConverterRequest converterRequest = new ConverterRequest(countryEnumDescription, countriesEnumDescription);
                // Query converter
                IWriterToRef<Country, Countries> converter = service.GetRequired<ConverterRequest, IWriterToRef<Country, Countries>>(converterRequest);
                // Convert
                Countries countries = converter.Read(Country.Finland);
                // </30>
            }
        }
    }
    
    // <98>
    [Flags]
    public enum Countries
    {
        Finland = 1,
        Sweden = 2,
        Norway = 4
    }
    
    public enum Country
    {
        Finland = 1,
        Sweden = 2,
        Norway = 3
    }
    // </98>
    
    // <99>
    public record MyRecord200
    {
        [EnumOf<string, Languages>(isFlags: true)]
        public string Languages { get; set; } = "Finnish";
    }
    
    public class Languages : IEnumerable<IEnumItem<object>>
    {
        IEnumItem<object>[] content = new IEnumItem<object>[] {
            new EnumItem("Languages:Finnish", "Finnish", "Finnish", "Finnish"),
            new EnumItem("Languages:Swedish", "Swedish", "Swedish", "Swedish"),
            new EnumItem("Languages:Norwegian", "Norwegian", "Norwegian", "Norwegian"),
        };
    
        public IEnumerator<IEnumItem<object>> GetEnumerator() => ((IEnumerable<IEnumItem<object>>)content).GetEnumerator();
        IEnumerator IEnumerable.GetEnumerator() => content.GetEnumerator();
    }
    
    [Flags]
    public enum Language2
    {
        Finnish = 1 << 0,
        Swedish = 1 << 1,
        Norwegian = 1 << 2
    }
    // </99>
    
    
    In This Article
    Back to top Copyright © Toni Kalajainen