Skip to content

Commit

Permalink
Merge pull request #341 from beppemarazzi/master
Browse files Browse the repository at this point in the history
fix interface for attributeGroup
  • Loading branch information
mganss authored Jun 24, 2022
2 parents ff78909 + 0e11080 commit 6525e3f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions XmlSchemaClassGenerator.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2747,5 +2747,51 @@ public void CollectionSetterInAttributeGroupInterfaceIsPublicIfCollectionSetterM
Assert.True(interfaceHasPublicSetter);
Assert.True(implementerHasPublicSetter);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void SimpleInterface(bool generateInterface)
{
const string xsd = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
<xs:attributeGroup name=""Common"">
<xs:attribute name=""name"" type=""xs:string""></xs:attribute>
</xs:attributeGroup>
<xs:complexType name=""A"">
<xs:attributeGroup ref=""Common""/>
</xs:complexType>
<xs:complexType name=""B"">
<xs:attributeGroup ref=""Common""/>
</xs:complexType>
</xs:schema>";

var generator = new Generator
{
NamespaceProvider = new NamespaceProvider
{
GenerateNamespace = key => "Test",
},
GenerateInterfaces = generateInterface,
};
var contents = ConvertXml(nameof(SimpleInterface) + $"({generateInterface})", xsd, generator).ToArray();
var assembly = Compiler.Compile(nameof(CollectionSetterInAttributeGroupInterfaceIsPublicIfCollectionSetterModeIsPublic), contents);

var interfaceCommon = assembly.GetType("Test.ICommon");
var typeA = assembly.GetType("Test.A");
var typeB = assembly.GetType("Test.B");
if(generateInterface)
{
Assert.True(interfaceCommon.IsInterface);
Assert.True(interfaceCommon.IsAssignableFrom(typeA));
Assert.True(interfaceCommon.IsAssignableFrom(typeB));
}
else
{
Assert.Null(interfaceCommon);
}
}
}
}
2 changes: 1 addition & 1 deletion XmlSchemaClassGenerator/ModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ private TypeModel CreateTypeModel(XmlSchemaComplexType complexType)
classModel.Properties.AddRange(attributeProperties);

if (_configuration.GenerateInterfaces)
AddInterfaces(classModel, items);
AddInterfaces(classModel, attributes);
}

XmlSchemaAnyAttribute anyAttribute = null;
Expand Down

0 comments on commit 6525e3f

Please sign in to comment.