Skip to content

Commit

Permalink
Fix GetIntegerDerivedType
Browse files Browse the repository at this point in the history
  • Loading branch information
kronic committed Aug 8, 2023
1 parent 7287932 commit 4e3182e
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions XmlSchemaClassGenerator/CodeUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,40 @@ private static Type GetIntegerDerivedType(XmlSchemaDatatype xml, GeneratorConfig
_ => typeof(decimal),
};

Type FromDigitRestriction(TotalDigitsRestrictionModel totalDigits) => xml.TypeCode switch
Type FromDigitRestriction(TotalDigitsRestrictionModel totalDigits
) => xml.TypeCode switch
{
XmlTypeCode.PositiveInteger or XmlTypeCode.NonNegativeInteger => totalDigits?.Value switch
{
< 3 => typeof(byte),
< 5 => typeof(ushort),
< 10 => typeof(uint),
< 20 => typeof(ulong),
< 30 => typeof(decimal),
_ => null
},
XmlTypeCode.Integer or XmlTypeCode.NegativeInteger or XmlTypeCode.NonPositiveInteger => totalDigits?.Value switch
{
< 3 => typeof(sbyte),
< 5 => typeof(short),
< 10 => typeof(int),
< 19 => typeof(long),
< 29 => typeof(decimal),
_ => null
},
_ => null,
XmlTypeCode.PositiveInteger or XmlTypeCode.NonNegativeInteger => totalDigits?.Value switch
{
< 3 => typeof(byte),
< 5 => typeof(ushort),
< 10 => typeof(uint),
< 20 => typeof(ulong),
< 30 => typeof(decimal),
_ => null
},
XmlTypeCode.Integer or XmlTypeCode.NegativeInteger or XmlTypeCode.NonPositiveInteger => totalDigits
?.Value switch
{
< 3 => typeof(sbyte),
< 5 => typeof(short),
< 10 => typeof(int),
< 19 => typeof(long),
< 29 => typeof(decimal),
_ => null
},
XmlTypeCode.Decimal
when restrictions.OfType<FractionDigitsRestrictionModel>().SingleOrDefault() is { IsSupported: true, Value: 0 } => totalDigits
?.Value switch
{
< 3 => typeof(sbyte),
< 5 => typeof(short),
< 10 => typeof(int),
< 19 => typeof(long),
< 29 => typeof(decimal),
_ => null
},
_ => null

Check warning on line 109 in XmlSchemaClassGenerator/CodeUtilities.cs

View check run for this annotation

Codecov / codecov/patch

XmlSchemaClassGenerator/CodeUtilities.cs#L109

Added line #L109 was not covered by tests
};

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

0 comments on commit 4e3182e

Please sign in to comment.