Skip to content

Commit

Permalink
Fix #101
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ganss committed Feb 19, 2019
1 parent bf267dc commit 8920a53
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
28 changes: 27 additions & 1 deletion XmlSchemaClassGenerator.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,13 +739,39 @@ public void AssemblyVisibleIsInternalInterface()
Assert.Contains("internal partial interface INamedElement", content);
}

[Fact]
public void DecimalSeparatorTest()
{
// see https://github.com/mganss/XmlSchemaClassGenerator/issues/101

const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"" elementFormDefault=""qualified"" attributeFormDefault=""unqualified"">
<xs:complexType name=""NamedType"">
<xs:attribute name=""SomeAttr"" type=""xs:decimal"" default=""1.5"" />
</xs:complexType>
</xs:schema>";

var generator = new Generator
{
NamespaceProvider = new NamespaceProvider
{
GenerateNamespace = key => "Test",
},
GenerateInterfaces = true,
AssemblyVisible = true
};
var contents = ConvertXml(nameof(ComplexTypeWithAttributeGroupExtension), xsd, generator);
var content = Assert.Single(contents);

Assert.Contains("private decimal _someAttr = 1.5m;", content);
}

private static void CompareOutput(string expected, string actual)
{
string Normalize(string input) => Regex.Replace(input, @"[ \t]*\r\n", "\n");
Assert.Equal(Normalize(expected), Normalize(actual));
}


[Theory]
[InlineData(typeof(decimal), "decimal")]
[InlineData(typeof(long), "long")]
Expand Down
3 changes: 2 additions & 1 deletion XmlSchemaClassGenerator/TypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
Expand Down Expand Up @@ -1275,7 +1276,7 @@ public override CodeExpression GetDefaultValueFor(string defaultString, bool att
return rv;
}

return new CodePrimitiveExpression(Convert.ChangeType(defaultString, ValueType));
return new CodePrimitiveExpression(Convert.ChangeType(defaultString, ValueType, CultureInfo.InvariantCulture));
}

public IEnumerable<CodeAttributeDeclaration> GetRestrictionAttributes()
Expand Down

0 comments on commit 8920a53

Please sign in to comment.