From 4e3182ec8d8ef4e6115bd9135efec5b447223845 Mon Sep 17 00:00:00 2001 From: kronic Date: Tue, 8 Aug 2023 14:49:00 +0300 Subject: [PATCH] Fix GetIntegerDerivedType --- XmlSchemaClassGenerator/CodeUtilities.cs | 53 +++++++++++++++--------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/XmlSchemaClassGenerator/CodeUtilities.cs b/XmlSchemaClassGenerator/CodeUtilities.cs index d7a050f7..997aa2b5 100644 --- a/XmlSchemaClassGenerator/CodeUtilities.cs +++ b/XmlSchemaClassGenerator/CodeUtilities.cs @@ -73,27 +73,40 @@ private static Type GetIntegerDerivedType(XmlSchemaDatatype xml, GeneratorConfig _ => typeof(decimal), }; - Type FromDigitRestriction(TotalDigitsRestrictionModel totalDigits) => xml.TypeCode switch + Type FromDigitRestriction(TotalDigitsRestrictionModel totalDigits + ) => xml.TypeCode switch { - XmlTypeCode.PositiveInteger or XmlTypeCode.NonNegativeInteger => totalDigits?.Value switch - { - < 3 => typeof(byte), - < 5 => typeof(ushort), - < 10 => typeof(uint), - < 20 => typeof(ulong), - < 30 => typeof(decimal), - _ => null - }, - XmlTypeCode.Integer or XmlTypeCode.NegativeInteger or XmlTypeCode.NonPositiveInteger => totalDigits?.Value switch - { - < 3 => typeof(sbyte), - < 5 => typeof(short), - < 10 => typeof(int), - < 19 => typeof(long), - < 29 => typeof(decimal), - _ => null - }, - _ => null, + XmlTypeCode.PositiveInteger or XmlTypeCode.NonNegativeInteger => totalDigits?.Value switch + { + < 3 => typeof(byte), + < 5 => typeof(ushort), + < 10 => typeof(uint), + < 20 => typeof(ulong), + < 30 => typeof(decimal), + _ => null + }, + XmlTypeCode.Integer or XmlTypeCode.NegativeInteger or XmlTypeCode.NonPositiveInteger => totalDigits + ?.Value switch + { + < 3 => typeof(sbyte), + < 5 => typeof(short), + < 10 => typeof(int), + < 19 => typeof(long), + < 29 => typeof(decimal), + _ => null + }, + XmlTypeCode.Decimal + when restrictions.OfType().SingleOrDefault() is { IsSupported: true, Value: 0 } => totalDigits + ?.Value switch + { + < 3 => typeof(sbyte), + < 5 => typeof(short), + < 10 => typeof(int), + < 19 => typeof(long), + < 29 => typeof(decimal), + _ => null + }, + _ => null }; Type FromFallback() => configuration.UseIntegerDataTypeAsFallback && configuration.IntegerDataType != null ? configuration.IntegerDataType : typeof(string);