Skip to content

Commit 4e3182e

Browse files
committed
Fix GetIntegerDerivedType
1 parent 7287932 commit 4e3182e

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

XmlSchemaClassGenerator/CodeUtilities.cs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,40 @@ private static Type GetIntegerDerivedType(XmlSchemaDatatype xml, GeneratorConfig
7373
_ => typeof(decimal),
7474
};
7575

76-
Type FromDigitRestriction(TotalDigitsRestrictionModel totalDigits) => xml.TypeCode switch
76+
Type FromDigitRestriction(TotalDigitsRestrictionModel totalDigits
77+
) => xml.TypeCode switch
7778
{
78-
XmlTypeCode.PositiveInteger or XmlTypeCode.NonNegativeInteger => totalDigits?.Value switch
79-
{
80-
< 3 => typeof(byte),
81-
< 5 => typeof(ushort),
82-
< 10 => typeof(uint),
83-
< 20 => typeof(ulong),
84-
< 30 => typeof(decimal),
85-
_ => null
86-
},
87-
XmlTypeCode.Integer or XmlTypeCode.NegativeInteger or XmlTypeCode.NonPositiveInteger => totalDigits?.Value switch
88-
{
89-
< 3 => typeof(sbyte),
90-
< 5 => typeof(short),
91-
< 10 => typeof(int),
92-
< 19 => typeof(long),
93-
< 29 => typeof(decimal),
94-
_ => null
95-
},
96-
_ => null,
79+
XmlTypeCode.PositiveInteger or XmlTypeCode.NonNegativeInteger => totalDigits?.Value switch
80+
{
81+
< 3 => typeof(byte),
82+
< 5 => typeof(ushort),
83+
< 10 => typeof(uint),
84+
< 20 => typeof(ulong),
85+
< 30 => typeof(decimal),
86+
_ => null
87+
},
88+
XmlTypeCode.Integer or XmlTypeCode.NegativeInteger or XmlTypeCode.NonPositiveInteger => totalDigits
89+
?.Value switch
90+
{
91+
< 3 => typeof(sbyte),
92+
< 5 => typeof(short),
93+
< 10 => typeof(int),
94+
< 19 => typeof(long),
95+
< 29 => typeof(decimal),
96+
_ => null
97+
},
98+
XmlTypeCode.Decimal
99+
when restrictions.OfType<FractionDigitsRestrictionModel>().SingleOrDefault() is { IsSupported: true, Value: 0 } => totalDigits
100+
?.Value switch
101+
{
102+
< 3 => typeof(sbyte),
103+
< 5 => typeof(short),
104+
< 10 => typeof(int),
105+
< 19 => typeof(long),
106+
< 29 => typeof(decimal),
107+
_ => null
108+
},
109+
_ => null
97110
};
98111

99112
Type FromFallback() => configuration.UseIntegerDataTypeAsFallback && configuration.IntegerDataType != null ? configuration.IntegerDataType : typeof(string);

0 commit comments

Comments
 (0)