Skip to content

Commit 729c1b5

Browse files
author
Michael Ganss
committed
Add support for ParseLimitsInInvariantCulture and ConvertValueInInvariantCulture (fixes #268)
1 parent 5c1c3e5 commit 729c1b5

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

XmlSchemaClassGenerator.Tests/xsd/simple/restriction.xsd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,17 @@
88
</xsd:complexContent>
99
</xsd:complexType>
1010
</xsd:element>
11+
<xsd:simpleType name="DecimalLimitedType">
12+
<xsd:restriction base="xsd:decimal">
13+
<xsd:minInclusive value="10.00"/>
14+
<xsd:maxInclusive value="24.99"/>
15+
</xsd:restriction>
16+
</xsd:simpleType>
17+
<xsd:element name="minmax">
18+
<xsd:complexType>
19+
<xsd:sequence>
20+
<xsd:element name="val" type="DecimalLimitedType"></xsd:element>
21+
</xsd:sequence>
22+
</xsd:complexType>
23+
</xsd:element>
1124
</xsd:schema>

XmlSchemaClassGenerator/TypeModel.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,11 +1523,27 @@ public IEnumerable<CodeAttributeDeclaration> GetRestrictionAttributes()
15231523

15241524
if (minInclusive != null && maxInclusive != null)
15251525
{
1526-
yield return new CodeAttributeDeclaration(
1527-
CodeUtilities.CreateTypeReference(typeof(RangeAttribute), Configuration),
1528-
new CodeAttributeArgument(new CodeTypeOfExpression(minInclusive.Type)),
1529-
new CodeAttributeArgument(new CodePrimitiveExpression(minInclusive.Value)),
1530-
new CodeAttributeArgument(new CodePrimitiveExpression(maxInclusive.Value)));
1526+
var rangeAttribute = new CodeAttributeDeclaration(
1527+
CodeUtilities.CreateTypeReference(typeof(RangeAttribute), Configuration),
1528+
new CodeAttributeArgument(new CodeTypeOfExpression(minInclusive.Type)),
1529+
new CodeAttributeArgument(new CodePrimitiveExpression(minInclusive.Value)),
1530+
new CodeAttributeArgument(new CodePrimitiveExpression(maxInclusive.Value)));
1531+
1532+
// see https://github.com/mganss/XmlSchemaClassGenerator/issues/268
1533+
if (Configuration.NetCoreSpecificCode)
1534+
{
1535+
if (minInclusive.Value.Contains(".") || maxInclusive.Value.Contains("."))
1536+
{
1537+
rangeAttribute.Arguments.Add(new CodeAttributeArgument("ParseLimitsInInvariantCulture", new CodePrimitiveExpression(true)));
1538+
}
1539+
1540+
if (minInclusive.Type != typeof(int) && minInclusive.Type != typeof(double))
1541+
{
1542+
rangeAttribute.Arguments.Add(new CodeAttributeArgument("ConvertValueInInvariantCulture", new CodePrimitiveExpression(true)));
1543+
}
1544+
}
1545+
1546+
yield return rangeAttribute;
15311547
}
15321548
}
15331549
}

0 commit comments

Comments
 (0)