Skip to content

Commit

Permalink
generated Form fixed for ref-elements
Browse files Browse the repository at this point in the history
  • Loading branch information
wetzel-fabian committed Feb 2, 2022
1 parent 438972e commit c52f248
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions XmlSchemaClassGenerator.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1810,10 +1810,10 @@ public void RefTypesGetNoXmlElementAttributeTest()
Assert.NotNull(classType);

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

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

[Fact]
Expand Down
11 changes: 10 additions & 1 deletion XmlSchemaClassGenerator/ModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -912,14 +912,23 @@ private IEnumerable<PropertyModel> 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,
XmlParent = item.XmlParent,
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);
Expand Down

0 comments on commit c52f248

Please sign in to comment.