Skip to content

Commit 48e9dfc

Browse files
committed
Set AllowEmptyStrings=false if min length is > 0 (fixes #549)
1 parent b8c850b commit 48e9dfc

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

XmlSchemaClassGenerator/TypeModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,9 @@ public void AddMembersTo(CodeTypeDeclaration typeDeclaration, bool withDataBindi
760760
if (IsRequired && Configuration.DataAnnotationMode != DataAnnotationMode.None)
761761
{
762762
var requiredAttribute = new CodeAttributeDeclaration(CodeUtilities.CreateTypeReference(Attributes.Required, Configuration));
763-
var allowEmptyStringsArgument = new CodeAttributeArgument("AllowEmptyStrings", new CodePrimitiveExpression(true));
763+
var noEmptyStrings = propertyType is SimpleModel simpleModel
764+
&& simpleModel.Restrictions.Any(r => r is MinLengthRestrictionModel m && m.Value > 0);
765+
var allowEmptyStringsArgument = new CodeAttributeArgument("AllowEmptyStrings", new CodePrimitiveExpression(!noEmptyStrings));
764766
requiredAttribute.Arguments.Add(allowEmptyStringsArgument);
765767
member.CustomAttributes.Add(requiredAttribute);
766768
}

0 commit comments

Comments
 (0)