How to define an enum with string value?

后端 未结 18 1412
一生所求
一生所求 2020-12-12 14:53

I am trying to define an Enum and add valid common separators which used in CSV or similar files. Then I am going to bind it to a ComboBox as a dat

18条回答
  •  星月不相逢
    2020-12-12 15:18

    It is kind of late for answer, but maybe it helps someone in future. I found it easier to use struct for this kind of problem.

    Following sample is copy pasted part from MS code:

    namespace System.IdentityModel.Tokens.Jwt
    {
        //
        // Summary:
        //     List of registered claims from different sources http://tools.ietf.org/html/rfc7519#section-4
        //     http://openid.net/specs/openid-connect-core-1_0.html#IDToken
        public struct JwtRegisteredClaimNames
        {
            //
            // Summary:
            //     http://tools.ietf.org/html/rfc7519#section-4
            public const string Actort = "actort";
            //
            // Summary:
            //     http://tools.ietf.org/html/rfc7519#section-4
            public const string Typ = "typ";
            //
            // Summary:
            //     http://tools.ietf.org/html/rfc7519#section-4
            public const string Sub = "sub";
            //
            // Summary:
            //     http://openid.net/specs/openid-connect-frontchannel-1_0.html#OPLogout
            public const string Sid = "sid";
            //
            // Summary:
            //     http://tools.ietf.org/html/rfc7519#section-4
            public const string Prn = "prn";
            //
            // Summary:
            //     http://tools.ietf.org/html/rfc7519#section-4
            public const string Nbf = "nbf";
            //
            // Summary:
            //     http://tools.ietf.org/html/rfc7519#section-4
            public const string Nonce = "nonce";
            //
            // Summary:
            //     http://tools.ietf.org/html/rfc7519#section-4
            public const string NameId = "nameid";
    
        }
    }
    

提交回复
热议问题