From 1a94497de44cfc0664a569c7ee14a288d9780736 Mon Sep 17 00:00:00 2001 From: Michael Ganss Date: Tue, 28 Jul 2020 17:21:52 +0200 Subject: [PATCH 1/2] Fix #217 --- XmlSchemaClassGenerator/ModelBuilder.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/XmlSchemaClassGenerator/ModelBuilder.cs b/XmlSchemaClassGenerator/ModelBuilder.cs index d092d368..835a860e 100644 --- a/XmlSchemaClassGenerator/ModelBuilder.cs +++ b/XmlSchemaClassGenerator/ModelBuilder.cs @@ -416,7 +416,20 @@ private TypeModel CreateTypeModel(Uri source, XmlSchemaComplexType complexType, // If it's a restriction, do not duplicate attributes on the derived class, they're already in the base class. // See https://msdn.microsoft.com/en-us/library/f3z3wh0y.aspx } - else { attributes = complexType.Attributes; } + else + { + attributes = complexType.Attributes; + + if (attributes.Count == 0 && complexType.ContentModel != null) + { + var content = complexType.ContentModel.Content; + + if (content is XmlSchemaComplexContentExtension extension) + attributes = extension.Attributes; + else if (content is XmlSchemaComplexContentRestriction restriction) + attributes = restriction.Attributes; + } + } if (attributes != null) { From c9d50eab88057e7c88d64a2280f81ca4f267fec0 Mon Sep 17 00:00:00 2001 From: Michael Ganss Date: Tue, 28 Jul 2020 17:28:51 +0200 Subject: [PATCH 2/2] Add test for #217 --- .../XmlSchemaClassGenerator.Tests.csproj | 3 +++ XmlSchemaClassGenerator.Tests/XmlTests.cs | 2 +- .../xsd/simple/restriction.xsd | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 XmlSchemaClassGenerator.Tests/xsd/simple/restriction.xsd diff --git a/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj b/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj index 8ed4684d..ddc2fe4f 100644 --- a/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj +++ b/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj @@ -576,6 +576,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/XmlSchemaClassGenerator.Tests/XmlTests.cs b/XmlSchemaClassGenerator.Tests/XmlTests.cs index 3f8c5002..73fb53dd 100644 --- a/XmlSchemaClassGenerator.Tests/XmlTests.cs +++ b/XmlSchemaClassGenerator.Tests/XmlTests.cs @@ -84,7 +84,7 @@ private IEnumerable ConvertXml(string name, string xsd, Generator genera const string IS24ImmoTransferPattern = @"xsd\is24immotransfer\is24immotransfer.xsd"; const string WadlPattern = @"xsd\wadl\*.xsd"; const string ListPattern = @"xsd\list\list.xsd"; - const string SimplePattern = @"xsd\simple\simple.xsd"; + const string SimplePattern = @"xsd\simple\*.xsd"; const string ArrayOrderPattern = @"xsd\array-order\array-order.xsd"; const string ClientPattern = @"xsd\client\client.xsd"; const string IataPattern = @"xsd\iata\*.xsd"; diff --git a/XmlSchemaClassGenerator.Tests/xsd/simple/restriction.xsd b/XmlSchemaClassGenerator.Tests/xsd/simple/restriction.xsd new file mode 100644 index 00000000..47c52e0e --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/simple/restriction.xsd @@ -0,0 +1,11 @@ + + + + + + + + + + +