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

csharp.validatable.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{#discriminator}}
        /// 
        /// To validate all properties of the instance
        /// 
        /// Validation context
        /// Validation Result
        IEnumerable IValidatableObject.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}}
  {{#parent}}
        /// 
        /// To validate all properties of the instance
        /// 
        /// Validation context
        /// Validation Result
        IEnumerable IValidatableObject.Validate(ValidationContext validationContext)
        {
            return this.BaseValidate(validationContext);
        }

        /// 
        /// To validate all properties of the instance
        /// 
        /// Validation context
        /// Validation Result
        protected IEnumerable BaseValidate(ValidationContext validationContext)
        {
  {{/parent}}
  {{^parent}}
        /// 
        /// To validate all properties of the instance
        /// 
        /// Validation context
        /// Validation Result
        IEnumerable IValidatableObject.Validate(ValidationContext validationContext)
        {
  {{/parent}}
{{/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 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 ValidationResult("Invalid value for {{{name}}}, length must be greater than {{minLength}}.", new [] { "{{{name}}}" });
            }

            {{/minLength}}
            {{#maximum}}
            // {{{name}}} ({{{dataType}}}) maximum
            if ({{#useGenericHost}}{{^required}}this.{{{name}}}Option.IsSet && {{/required}}{{/useGenericHost}}this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} > ({{{dataType}}}){{maximum}})
            {
                yield return new ValidationResult("Invalid value for {{{name}}}, must be a value less than or equal to {{maximum}}.", new [] { "{{{name}}}" });
            }

            {{/maximum}}
            {{#minimum}}
            // {{{name}}} ({{{dataType}}}) minimum
            if ({{#useGenericHost}}{{^required}}this.{{{name}}}Option.IsSet && {{/required}}{{/useGenericHost}}this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} < ({{{dataType}}}){{minimum}})
            {
                yield return new ValidationResult("Invalid value for {{{name}}}, must be a value greater than or equal to {{minimum}}.", new [] { "{{{name}}}" });
            }

            {{/minimum}}
            {{#pattern}}
            {{^isByteArray}}
            {{#vendorExtensions.x-is-value-type}}
            {{#isNullable}}
            if (this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} != null){
                {{#lambda.trimTrailingWithNewLine}}
                {{#lambda.indent4}}
                {{>ValidateRegex}}
                {{/lambda.indent4}}

                {{/lambda.trimTrailingWithNewLine}}
            }

            {{/isNullable}}
            {{^isNullable}}
            {{#lambda.trimTrailingWithNewLine}}
            {{#lambda.indent3}}
            {{>ValidateRegex}}
            {{/lambda.indent3}}

            {{/lambda.trimTrailingWithNewLine}}
            {{/isNullable}}
            {{/vendorExtensions.x-is-value-type}}
            {{^vendorExtensions.x-is-value-type}}
            if (this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} != null) {
                {{#lambda.trimTrailingWithNewLine}}
                {{#lambda.indent4}}
                {{>ValidateRegex}}
                {{/lambda.indent4}}

                {{/lambda.trimTrailingWithNewLine}}
            }

            {{/vendorExtensions.x-is-value-type}}
            {{/isByteArray}}
            {{/pattern}}
            {{/isEnum}}
            {{/hasValidation}}
            {{/vars}}
            yield break;
        }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy