Skip to content

Commit c52f248

Browse files
committed
generated Form fixed for ref-elements
1 parent 438972e commit c52f248

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

XmlSchemaClassGenerator.Tests/XmlTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,10 +1810,10 @@ public void RefTypesGetNoXmlElementAttributeTest()
18101810
Assert.NotNull(classType);
18111811

18121812
var directProperty = Assert.Single(classType.GetProperties().Where(p => p.Name == "Direct"));
1813-
Assert.NotEmpty(directProperty.GetCustomAttributes<XmlElementAttribute>());
1813+
Assert.Equal(XmlSchemaForm.Unqualified, directProperty.GetCustomAttributes<XmlElementAttribute>().FirstOrDefault()?.Form);
18141814

18151815
var viaRefProperty = Assert.Single(classType.GetProperties().Where(p => p.Name == "ViaRef"));
1816-
Assert.Empty(viaRefProperty.GetCustomAttributes<XmlElementAttribute>());
1816+
Assert.Equal(XmlSchemaForm.None, viaRefProperty.GetCustomAttributes<XmlElementAttribute>().FirstOrDefault()?.Form);
18171817
}
18181818

18191819
[Fact]

XmlSchemaClassGenerator/ModelBuilder.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,14 +912,23 @@ private IEnumerable<PropertyModel> CreatePropertiesForElements(Uri source, TypeM
912912
IsCollection = item.MaxOccurs > 1.0m || particle.MaxOccurs > 1.0m, // http://msdn.microsoft.com/en-us/library/vstudio/d3hx2s7e(v=vs.100).aspx
913913
DefaultValue = element.DefaultValue ?? ((item.MinOccurs >= 1.0m && item.XmlParent is not XmlSchemaChoice) ? element.FixedValue : null),
914914
FixedValue = element.FixedValue,
915-
Form = element.Form == XmlSchemaForm.None ? element.GetSchema().ElementFormDefault : element.Form,
916915
XmlNamespace = !string.IsNullOrEmpty(effectiveElement.QualifiedName.Namespace) && effectiveElement.QualifiedName.Namespace != typeModel.XmlSchemaName.Namespace
917916
? effectiveElement.QualifiedName.Namespace : null,
918917
XmlParticle = item.XmlParticle,
919918
XmlParent = item.XmlParent,
920919
Particle = item
921920
};
922921

922+
if (element.Form == XmlSchemaForm.None)
923+
{
924+
if (element.RefName != null && !element.RefName.IsEmpty)
925+
property.Form = XmlSchemaForm.Qualified;
926+
else
927+
property.Form = element.GetSchema().ElementFormDefault;
928+
}
929+
else
930+
property.Form = element.Form;
931+
923932
if (property.IsArray && !_configuration.GenerateComplexTypesForCollections)
924933
{
925934
property.Type.Namespace.Types.Remove(property.Type.Name);

0 commit comments

Comments
 (0)