diff --git a/XmlSchemaClassGenerator.Tests/XmlTests.cs b/XmlSchemaClassGenerator.Tests/XmlTests.cs
index 4b8b0f0e..0c377936 100644
--- a/XmlSchemaClassGenerator.Tests/XmlTests.cs
+++ b/XmlSchemaClassGenerator.Tests/XmlTests.cs
@@ -1765,6 +1765,57 @@ public void RenameInterfacePropertyInDerivedClassTest()
Assert.Equal("ClassItemBaseProperty", level3Interface.GetProperties().First().Name);
}
+ [Fact]
+ public void RefTypesGetNoXmlElementAttributeTest()
+ {
+ const string xsd = @"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+";
+
+ var generator = new Generator
+ {
+ NamespaceProvider = new NamespaceProvider
+ {
+ GenerateNamespace = key => "Test"
+ },
+ GenerateInterfaces = true,
+ AssemblyVisible = true
+ };
+ var contents = ConvertXml(nameof(RefTypesGetNoXmlElementAttributeTest), xsd, generator);
+ var content = Assert.Single(contents);
+
+ var assembly = Compiler.Compile(nameof(RefTypesGetNoXmlElementAttributeTest), content);
+ var classType = assembly.GetType("Test.SampleRoot");
+ Assert.NotNull(classType);
+
+ var directProperty = Assert.Single(classType.GetProperties().Where(p => p.Name == "Direct"));
+ Assert.Equal(XmlSchemaForm.Unqualified, directProperty.GetCustomAttributes().FirstOrDefault()?.Form);
+
+ var viaRefProperty = Assert.Single(classType.GetProperties().Where(p => p.Name == "ViaRef"));
+ Assert.Equal(XmlSchemaForm.None, viaRefProperty.GetCustomAttributes().FirstOrDefault()?.Form);
+ }
+
[Fact]
public void DoNotGenerateSamePropertiesInDerivedInterfacesClassTest()
{
diff --git a/XmlSchemaClassGenerator/ModelBuilder.cs b/XmlSchemaClassGenerator/ModelBuilder.cs
index a11d25c5..51dea5db 100644
--- a/XmlSchemaClassGenerator/ModelBuilder.cs
+++ b/XmlSchemaClassGenerator/ModelBuilder.cs
@@ -912,7 +912,6 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM
IsCollection = item.MaxOccurs > 1.0m || particle.MaxOccurs > 1.0m, // http://msdn.microsoft.com/en-us/library/vstudio/d3hx2s7e(v=vs.100).aspx
DefaultValue = element.DefaultValue ?? ((item.MinOccurs >= 1.0m && item.XmlParent is not XmlSchemaChoice) ? element.FixedValue : null),
FixedValue = element.FixedValue,
- Form = element.Form == XmlSchemaForm.None ? element.GetSchema().ElementFormDefault : element.Form,
XmlNamespace = !string.IsNullOrEmpty(effectiveElement.QualifiedName.Namespace) && effectiveElement.QualifiedName.Namespace != typeModel.XmlSchemaName.Namespace
? effectiveElement.QualifiedName.Namespace : null,
XmlParticle = item.XmlParticle,
@@ -920,6 +919,16 @@ private IEnumerable CreatePropertiesForElements(Uri source, TypeM
Particle = item
};
+ if (element.Form == XmlSchemaForm.None)
+ {
+ if (element.RefName != null && !element.RefName.IsEmpty)
+ property.Form = XmlSchemaForm.Qualified;
+ else
+ property.Form = element.GetSchema().ElementFormDefault;
+ }
+ else
+ property.Form = element.Form;
+
if (property.IsArray && !_configuration.GenerateComplexTypesForCollections)
{
property.Type.Namespace.Types.Remove(property.Type.Name);