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; } } }