From 729c1b52fb8f321356ddd1a0f9535dd52ad8104f Mon Sep 17 00:00:00 2001 From: Michael Ganss Date: Thu, 27 May 2021 14:03:10 +0200 Subject: [PATCH] Add support for ParseLimitsInInvariantCulture and ConvertValueInInvariantCulture (fixes #268) --- .../xsd/simple/restriction.xsd | 13 ++++++++++ XmlSchemaClassGenerator/TypeModel.cs | 26 +++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/XmlSchemaClassGenerator.Tests/xsd/simple/restriction.xsd b/XmlSchemaClassGenerator.Tests/xsd/simple/restriction.xsd index 47c52e0e..20170ddd 100644 --- a/XmlSchemaClassGenerator.Tests/xsd/simple/restriction.xsd +++ b/XmlSchemaClassGenerator.Tests/xsd/simple/restriction.xsd @@ -8,4 +8,17 @@ + + + + + + + + + + + + + diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs index 4af8b7cb..338f527c 100644 --- a/XmlSchemaClassGenerator/TypeModel.cs +++ b/XmlSchemaClassGenerator/TypeModel.cs @@ -1523,11 +1523,27 @@ public IEnumerable GetRestrictionAttributes() if (minInclusive != null && maxInclusive != null) { - yield return new CodeAttributeDeclaration( - CodeUtilities.CreateTypeReference(typeof(RangeAttribute), Configuration), - new CodeAttributeArgument(new CodeTypeOfExpression(minInclusive.Type)), - new CodeAttributeArgument(new CodePrimitiveExpression(minInclusive.Value)), - new CodeAttributeArgument(new CodePrimitiveExpression(maxInclusive.Value))); + var rangeAttribute = new CodeAttributeDeclaration( + CodeUtilities.CreateTypeReference(typeof(RangeAttribute), Configuration), + new CodeAttributeArgument(new CodeTypeOfExpression(minInclusive.Type)), + new CodeAttributeArgument(new CodePrimitiveExpression(minInclusive.Value)), + new CodeAttributeArgument(new CodePrimitiveExpression(maxInclusive.Value))); + + // see https://github.com/mganss/XmlSchemaClassGenerator/issues/268 + if (Configuration.NetCoreSpecificCode) + { + if (minInclusive.Value.Contains(".") || maxInclusive.Value.Contains(".")) + { + rangeAttribute.Arguments.Add(new CodeAttributeArgument("ParseLimitsInInvariantCulture", new CodePrimitiveExpression(true))); + } + + if (minInclusive.Type != typeof(int) && minInclusive.Type != typeof(double)) + { + rangeAttribute.Arguments.Add(new CodeAttributeArgument("ConvertValueInInvariantCulture", new CodePrimitiveExpression(true))); + } + } + + yield return rangeAttribute; } } }