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

csharp-netcore.validatable.mustache Maven / Gradle / Ivy

{{#discriminator}}
        /// 
        /// To validate all properties of the instance
        /// 
        /// Validation context
        /// Validation Result
        public IEnumerable Validate(ValidationContext validationContext)
        {
            return this.BaseValidate(validationContext);
        }

        /// 
        /// To validate all properties of the instance
        /// 
        /// Validation context
        /// Validation Result
        protected IEnumerable BaseValidate(ValidationContext validationContext)
        {
{{/discriminator}}
{{^discriminator}}
        /// 
        /// To validate all properties of the instance
        /// 
        /// Validation context
        /// Validation Result
        public IEnumerable Validate(ValidationContext validationContext)
        {
{{/discriminator}}
            {{#parent}}
            {{^isArray}}
            {{^isMap}}
            foreach (var x in {{#discriminator}}base.{{/discriminator}}BaseValidate(validationContext))
            {
                yield return x;
            }
            {{/isMap}}
            {{/isArray}}
            {{/parent}}
            {{#vars}}
            {{#hasValidation}}
            {{^isEnum}}
            {{#maxLength}}
            // {{{name}}} ({{{dataType}}}) maxLength
            if (this.{{{name}}} != null && this.{{{name}}}.Length > {{maxLength}})
            {
                yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, length must be less than {{maxLength}}.", new [] { "{{{name}}}" });
            }

            {{/maxLength}}
            {{#minLength}}
            // {{{name}}} ({{{dataType}}}) minLength
            if (this.{{{name}}} != null && this.{{{name}}}.Length < {{minLength}})
            {
                yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, length must be greater than {{minLength}}.", new [] { "{{{name}}}" });
            }

            {{/minLength}}
            {{#maximum}}
            // {{{name}}} ({{{dataType}}}) maximum
            if (this.{{{name}}} > ({{{dataType}}}){{maximum}})
            {
                yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must be a value less than or equal to {{maximum}}.", new [] { "{{{name}}}" });
            }

            {{/maximum}}
            {{#minimum}}
            // {{{name}}} ({{{dataType}}}) minimum
            if (this.{{{name}}} < ({{{dataType}}}){{minimum}})
            {
                yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must be a value greater than or equal to {{minimum}}.", new [] { "{{{name}}}" });
            }

            {{/minimum}}
            {{#pattern}}
            {{^isByteArray}}
            // {{{name}}} ({{{dataType}}}) pattern
            Regex regex{{{name}}} = new Regex(@"{{{vendorExtensions.x-regex}}}"{{#vendorExtensions.x-modifiers}}{{#-first}}, {{/-first}}RegexOptions.{{{.}}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}});
            if (false == regex{{{name}}}.Match(this.{{{name}}}{{#isUuid}}.ToString(){{/isUuid}}).Success)
            {
                yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must match a pattern of " + regex{{{name}}}, new [] { "{{{name}}}" });
            }

            {{/isByteArray}}
            {{/pattern}}
            {{/isEnum}}
            {{/hasValidation}}
            {{/vars}}
            yield break;
        }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy