Skip to content

Commit

Permalink
Make EmitOrder work for arrays. Fixes #126
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan Glasson authored and Logan Glasson committed Sep 3, 2019
1 parent 827a00c commit 56c67a5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
3 changes: 2 additions & 1 deletion XmlSchemaClassGenerator.Tests/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public static Assembly GenerateFiles(string name, IEnumerable<string> files, Gen
MemberVisitor = generatorPrototype.MemberVisitor,
GenerateDescriptionAttribute = generatorPrototype.GenerateDescriptionAttribute,
CodeTypeReferenceOptions = generatorPrototype.CodeTypeReferenceOptions,
TextValuePropertyName = generatorPrototype.TextValuePropertyName
TextValuePropertyName = generatorPrototype.TextValuePropertyName,
EmitOrder = generatorPrototype.EmitOrder
};

gen.Generate(files);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@
<None Update="xml\tradeSite_min.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xsd\array-order\array-order.xsd">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xsd\client\client.xsd">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
13 changes: 13 additions & 0 deletions XmlSchemaClassGenerator.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private IEnumerable<string> ConvertXml(string name, string xsd, Generator genera
const string WadlPattern = @"xsd\wadl\*.xsd";
const string ListPattern = @"xsd\list\list.xsd";
const string SimplePattern = @"xsd\simple\simple.xsd";
const string ArrayOrderPattern = @"xsd\array-order\array-order.xsd";
const string ClientPattern = @"xsd\client\client.xsd";
const string IataPattern = @"xsd\iata\*.xsd";
const string TimePattern = @"xsd\time\time.xsd";
Expand Down Expand Up @@ -131,6 +132,18 @@ public void TestSimple()
TestSamples("Simple", SimplePattern);
}

[Fact, TestPriority(1)]
[UseCulture("en-US")]
public void TestArrayOrder()
{
Compiler.Generate("ArrayOrder", ArrayOrderPattern, new Generator
{
NamespacePrefix = "ArrayOrder",
EmitOrder = true
});
TestSamples("ArrayOrder", ArrayOrderPattern);
}

[Fact, TestPriority(1)]
[UseCulture("en-US")]
public void TestIS24RestApi()
Expand Down
24 changes: 24 additions & 0 deletions XmlSchemaClassGenerator.Tests/xsd/array-order/array-order.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="P">
<xs:complexType>
<xs:sequence>
<xs:element name="A" type="xs:string"/>
<xs:element name="B" type="Q" minOccurs="0"/>
<xs:element name="C" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Q">
<xs:sequence>
<xs:element name="R" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="D" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>

7 changes: 5 additions & 2 deletions XmlSchemaClassGenerator/TypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,8 +1048,11 @@ private IEnumerable<CodeAttributeDeclaration> GetAttributes(bool isArray)
}
else
{
attributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlArrayAttribute), Configuration.CodeTypeReferenceOptions),
new CodeAttributeArgument(new CodePrimitiveExpression(XmlSchemaName.Name))));
var arrayAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlArrayAttribute), Configuration.CodeTypeReferenceOptions),
new CodeAttributeArgument(new CodePrimitiveExpression(XmlSchemaName.Name)));
if (Order != null)
arrayAttribute.Arguments.Add(new CodeAttributeArgument("Order", new CodePrimitiveExpression(Order.Value)));
attributes.Add(arrayAttribute);
}

foreach (var attribute in attributes)
Expand Down

0 comments on commit 56c67a5

Please sign in to comment.