All Downloads are FREE. Search and download functionalities are using the official Maven repository.

csharp.modelInnerEnum.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
        {{^isContainer}}
        /// 
        /// {{description}}{{^description}}Defines {{{name}}}{{/description}}
        /// 
        {{#description}}
        /// {{.}}
        {{/description}}
        {{#isString}}
        {{^useGenericHost}}
        [JsonConverter(typeof(StringEnumConverter))]
        {{/useGenericHost}}
        {{/isString}}
        {{>visibility}} enum {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}{{#vendorExtensions.x-enum-byte}}: byte{{/vendorExtensions.x-enum-byte}}
        {
            {{#allowableValues}}
            {{#enumVars}}
            /// 
            /// Enum {{name}} for value: {{value}}
            /// 
            {{^useGenericHost}}
            {{#isString}}
            [EnumMember(Value = "{{{value}}}")]
            {{/isString}}
            {{/useGenericHost}}
            {{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}}{{^vendorExtensions.x-zero-based-enum}} = {{-index}}{{/vendorExtensions.x-zero-based-enum}}{{/isString}}{{^-last}},{{/-last}}
            {{^-last}}

            {{/-last}}
            {{/enumVars}}
            {{/allowableValues}}
        }
        {{#useGenericHost}}

        /// 
        /// Returns a 
        /// 
        /// 
        /// 
        /// 
        public static {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}FromString(string value)
        {
            {{#allowableValues}}
            {{#enumVars}}
            if (value.Equals({{^isString}}({{{value}}}).ToString(){{/isString}}{{#isString}}"{{{value}}}"{{/isString}}))
                return {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.{{name}};

            {{/enumVars}}
            {{/allowableValues}}
            throw new NotImplementedException($"Could not convert value to type {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}: '{value}'");
        }

        /// 
        /// Returns a 
        /// 
        /// 
        /// 
        public static {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}? {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}FromStringOrDefault(string value)
        {
            {{#allowableValues}}
            {{#enumVars}}
            if (value.Equals({{^isString}}({{{value}}}).ToString(){{/isString}}{{#isString}}"{{{value}}}"{{/isString}}))
                return {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.{{name}};

            {{/enumVars}}
            {{/allowableValues}}
            return null;
        }

        /// 
        /// Converts the  to the json value
        /// 
        /// 
        /// 
        {{#isString}}
        /// 
        {{/isString}}
        public static {{>EnumValueDataType}}{{#lambda.first}}{{#nrt}}{{#isString}}{{#isNullable}}{{nrt?}}  {{^nrt}}{{#vendorExtensions.x-is-value-type}}?  {{/vendorExtensions.x-is-value-type}}{{/nrt}}{{/isNullable}}{{/isString}}{{/nrt}}{{/lambda.first}} {{datatypeWithEnum}}ToJsonValue({{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}{{#isString}}{{>NullConditionalProperty}}{{/isString}} value)
        {
            {{^isString}}
            return ({{>EnumValueDataType}}) value;
            {{/isString}}
            {{#isString}}
            {{#isNullable}}
            if (value == null)
                return null;

            {{/isNullable}}
            {{#allowableValues}}
            {{#enumVars}}
            if (value == {{datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.{{name}})
                return {{^isNumeric}}"{{/isNumeric}}{{{value}}}{{^isNumeric}}"{{/isNumeric}};

            {{/enumVars}}
            {{/allowableValues}}
            throw new NotImplementedException($"Value could not be handled: '{value}'");
            {{/isString}}
        }
        {{/useGenericHost}}
        {{/isContainer}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy