From 3db1ee07e31296214c961182f84261b68adb4e62 Mon Sep 17 00:00:00 2001 From: Michael Ganss Date: Tue, 2 Jul 2024 16:03:03 +0200 Subject: [PATCH] Do not output duplicate StringLengthAttribute (fixes #521) --- XmlSchemaClassGenerator/CodeUtilities.cs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/XmlSchemaClassGenerator/CodeUtilities.cs b/XmlSchemaClassGenerator/CodeUtilities.cs index 550fb15..270e212 100644 --- a/XmlSchemaClassGenerator/CodeUtilities.cs +++ b/XmlSchemaClassGenerator/CodeUtilities.cs @@ -242,8 +242,15 @@ private static Type GetUnionType(GeneratorConfiguration configuration, XmlSchema public static IEnumerable GetRestrictions(IEnumerable facets, XmlSchemaSimpleType type, GeneratorConfiguration _configuration) { - var min = facets.OfType().Select(f => int.Parse(f.Value)).DefaultIfEmpty().Max(); - var max = facets.OfType().Select(f => int.Parse(f.Value)).DefaultIfEmpty().Min(); + var len = facets.OfType().Select(f => int.Parse(f.Value)).ToList(); + var min = facets.OfType().Select(f => int.Parse(f.Value)) + .Union(len) + .DefaultIfEmpty() + .Max(); + var max = facets.OfType().Select(f => int.Parse(f.Value)) + .Union(len) + .DefaultIfEmpty() + .Min(); if (_configuration.DataAnnotationMode == DataAnnotationMode.All) { @@ -260,18 +267,6 @@ public static IEnumerable GetRestrictions(IEnumerable