diff --git a/XmlSchemaClassGenerator.Tests/IntegerTypeTests.cs b/XmlSchemaClassGenerator.Tests/IntegerTypeTests.cs
index effa751f..5e7bbed6 100644
--- a/XmlSchemaClassGenerator.Tests/IntegerTypeTests.cs
+++ b/XmlSchemaClassGenerator.Tests/IntegerTypeTests.cs
@@ -65,15 +65,15 @@ public void TestTotalDigits(int totalDigits, string expectedType)
var xsd = @$"
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
";
@@ -99,15 +99,15 @@ public void TestFallbackType(int totalDigits, bool useTypeAsFallback, string exp
var xsd = @$"
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
";
@@ -147,16 +147,16 @@ public void TestInclusiveRange(long minInclusive, ulong maxInclusive, string exp
var xsd = @$"
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
";
@@ -173,5 +173,129 @@ public void TestInclusiveRange(long minInclusive, ulong maxInclusive, string exp
Assert.Contains(expectedProperty, generatedProperty);
}
- }
+
+ [Theory]
+ [InlineData(2, "sbyte")]
+ [InlineData(4, "short")]
+ [InlineData(9, "int")]
+ [InlineData(18, "long")]
+ [InlineData(28, "decimal")]
+ [InlineData(29, "string")]
+ public void TestDecimalFractionDigitsZeroTotalDigits(int totalDigits, string expectedType)
+ {
+ var xsd = @$"
+
+
+
+
+
+
+
+
+
+
+
+
+";
+
+ var generatedType = ConvertXml(nameof(TestTotalDigits), xsd, new Generator
+ {
+ NamespaceProvider = new NamespaceProvider
+ {
+ GenerateNamespace = key => "Test"
+ }
+ });
+
+ var expectedProperty = $"public {expectedType} SomeValue";
+ Assert.Contains(expectedProperty, generatedType.First());
+ }
+
+
+ [Theory]
+ [InlineData(4, false, "long")]
+ [InlineData(30, false, "long")]
+ [InlineData(4, true, "short")]
+ [InlineData(30, true, "long")]
+ public void TestDecimalFractionDigitsFallbackType(int totalDigits, bool useTypeAsFallback, string expectedType)
+ {
+ var xsd = @$"
+
+
+
+
+
+
+
+
+
+
+
+
+";
+
+ var generatedType = ConvertXml(nameof(TestTotalDigits), xsd, new Generator
+ {
+ NamespaceProvider = new NamespaceProvider
+ {
+ GenerateNamespace = key => "Test"
+ },
+ IntegerDataType = typeof(long),
+ UseIntegerDataTypeAsFallback = useTypeAsFallback
+ });
+
+ var expectedProperty = $"public {expectedType} SomeValue";
+ Assert.Contains(expectedProperty, generatedType.First());
+ }
+
+ [Theory]
+ [InlineData(1, 100, "byte")]
+ [InlineData(byte.MinValue, byte.MaxValue, "byte")]
+ [InlineData(-100, 100, "sbyte")]
+ [InlineData(sbyte.MinValue, sbyte.MaxValue, "sbyte")]
+ [InlineData(1, 1000, "ushort")]
+ [InlineData(ushort.MinValue, ushort.MaxValue, "ushort")]
+ [InlineData(-1000, 1000, "short")]
+ [InlineData(short.MinValue, short.MaxValue, "short")]
+ [InlineData(1, 100000, "uint")]
+ [InlineData(uint.MinValue, uint.MaxValue, "uint")]
+ [InlineData(-100000, 100000, "int")]
+ [InlineData(int.MinValue, int.MaxValue, "int")]
+ [InlineData(1, 10000000000, "ulong")]
+ [InlineData(ulong.MinValue, ulong.MaxValue, "ulong")]
+ [InlineData(-10000000000, 10000000000, "long")]
+ [InlineData(long.MinValue, long.MaxValue, "long")]
+ public void TestDecimalFractionDigitsZeroInclusiveRange(long minInclusive, ulong maxInclusive, string expectedType)
+ {
+ var xsd = @$"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+";
+
+ var generatedType = ConvertXml(nameof(TestTotalDigits), xsd, new Generator
+ {
+ NamespaceProvider = new NamespaceProvider
+ {
+ GenerateNamespace = key => "Test"
+ }
+ });
+
+ var expectedProperty = $"public {expectedType} SomeValue";
+ var generatedProperty = generatedType.First();
+
+ Assert.Contains(expectedProperty, generatedProperty);
+ }
+ }
+
}
diff --git a/XmlSchemaClassGenerator.Tests/SharedTestFunctions.cs b/XmlSchemaClassGenerator.Tests/SharedTestFunctions.cs
index e97b8796..a2299fe0 100644
--- a/XmlSchemaClassGenerator.Tests/SharedTestFunctions.cs
+++ b/XmlSchemaClassGenerator.Tests/SharedTestFunctions.cs
@@ -126,7 +126,7 @@ void validate2(object s, ValidationEventArgs e)
{
if (HandleValidationError(output, xmlLines, e))
throw e.Exception;
- };
+ }
settings.ValidationEventHandler += validate2;
diff --git a/XmlSchemaClassGenerator/CodeUtilities.cs b/XmlSchemaClassGenerator/CodeUtilities.cs
index 88b85b7b..d7a050f7 100644
--- a/XmlSchemaClassGenerator/CodeUtilities.cs
+++ b/XmlSchemaClassGenerator/CodeUtilities.cs
@@ -111,7 +111,8 @@ public static Type GetEffectiveType(this XmlSchemaDatatype type, GeneratorConfig
XmlTypeCode.Time => typeof(DateTime),
XmlTypeCode.Idref => typeof(string),
XmlTypeCode.Integer or XmlTypeCode.NegativeInteger or XmlTypeCode.NonNegativeInteger or XmlTypeCode.NonPositiveInteger or XmlTypeCode.PositiveInteger => GetIntegerDerivedType(type, configuration, restrictions),
- _ => type.ValueType,
+ XmlTypeCode.Decimal when restrictions.OfType().SingleOrDefault() is { IsSupported: true, Value: 0 } => GetIntegerDerivedType(type, configuration, restrictions),
+ _ => type.ValueType,
};
if (schemaType.IsDerivedFrom(GuidQualifiedName))