Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update modelGeneric.mustache
If maxlength is specified for a property type enum it there should be .ToString() appended before length check
  • Loading branch information
shwetashukla authored Feb 19, 2020
commit 7ac714cf6f6c504c35e644828215eada8d91b8d3
Original file line number Diff line number Diff line change
Expand Up @@ -259,22 +259,44 @@ this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/parent}}
{{#vars}}
{{#hasValidation}}
{{#isEnum}}
{{#maxLength}}
// {{{name}}} ({{{dataType}}}) maxLength
if(this.{{{name}}} != null && this.{{{name}}}.ToString().Length > {{maxLength}})
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, length must be less than {{maxLength}}.", new [] { "{{{name}}}" });
}
{{/maxLength}}
{{/isEnum}}
{{^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}}
{{/isEnum}}

{{#isEnum}}
{{#minLength}}
// {{{name}}} ({{{dataType}}}) minLength
if(this.{{{name}}} != null && this.{{{name}}}.ToString().Length < {{minLength}})
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, length must be greater than {{minLength}}.", new [] { "{{{name}}}" });
}
{{/minLength}}
{{/isEnum}}
{{^isEnum}}
{{#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}}
{{/isEnum}}

{{#maximum}}
// {{{name}}} ({{{dataType}}}) maximum
if(this.{{{name}}} > ({{{dataType}}}){{maximum}})
Expand Down