Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix interface for attributeGroup #341

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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