Click here to Skip to main content
15,884,388 members
Articles / Programming Languages / C#

Human-readable Enumeration Meta-data

Rate me:
Please Sign up or sign in to vote.
5.00/5 (44 votes)
8 Mar 2017CPOL16 min read 102.6K   574   80  
Display names and descriptions for enumeration members: a non-intrusive, reliable, localizeable method.
/*
    Samples code snippets for article
    "Working around Language Limitations: Making Enumerations Enumerate
     Generic classes for enumeration-based iteration and array indexing"
    
    Copyright (C) 2008-2010 by Sergey A Kryukov
    http://www.SAKryukov.org    
*/
namespace JustTests {

    internal class BitSetIteration {

        enum SearchOptionBitPosition {
            MatchCase, //other case-insensitive
            SearchBackward, //otherwise search forward
            UseRegularExpressions, 
            WholeText, //otherwise start from cursor
            Length,
        } //enum SearchOptionBitPosition

        [System.Flags]
        enum SearchOptions {
            Default = 0,
            MatchCase = 1 << SearchOptionBitPosition.MatchCase,
            SearchBackward = 1 << SearchOptionBitPosition.SearchBackward, //otherwise search forward
            UseRegularExpressions = 1 << SearchOptionBitPosition.UseRegularExpressions,
            WholeText = 1 << SearchOptionBitPosition.WholeText, //otherwise start from cursor
        } //enum SearchOptions

        internal void IterationSample() {

            SearchOptions options = SearchOptions.MatchCase | SearchOptions.UseRegularExpressions;
            bool caseSensitive = (options & SearchOptions.MatchCase) > 0;
            bool ignoreCase = (options & SearchOptions.MatchCase) > 0;

            for (SearchOptionBitPosition loopVariable = 0; loopVariable <= SearchOptionBitPosition.Length; loopVariable++) {
                SearchOptions option = (SearchOptions)(1 << (int)loopVariable);
                //use option and loopVarible
            } //loop CardSuit

        } //LengthDescriptorUse

    } //class BitSetIteration

} //namespace JustTests

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United States United States
Physics, physical and quantum optics, mathematics, computer science, control systems for manufacturing, diagnostics, testing, and research, theory of music, musical instruments… Contact me: https://www.SAKryukov.org

Comments and Discussions