Skip to content

Commit

Permalink
Emit XmlElementAttribute for substitutionGroups with an abstract head…
Browse files Browse the repository at this point in the history
…. See #36 (comment)
  • Loading branch information
John Welch committed Oct 4, 2018
1 parent ec95c6f commit 3bbbd06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions XmlSchemaClassGenerator/ModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public ModelBuilder(GeneratorConfiguration configuration, XmlSchemaSet set)
if (type is ClassModel classModel)
{
classModel.Documentation.AddRange(GetDocumentation(rootElement));
if (!rootElement.SubstitutionGroup.IsEmpty)
{
classModel.IsSubstitution = true;
classModel.SubstitutionName = rootElement.QualifiedName;
}
}

type.RootElementName = rootElement.QualifiedName;
Expand Down
3 changes: 2 additions & 1 deletion XmlSchemaClassGenerator/TypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public class ClassModel : TypeModel
public bool IsAbstract { get; set; }
public bool IsMixed { get; set; }
public bool IsSubstitution { get; set; }
public XmlQualifiedName SubstitutionName { get; set; }
public TypeModel BaseClass { get; set; }
public List<PropertyModel> Properties { get; set; }
public List<InterfaceModel> Interfaces { get; set; }
Expand Down Expand Up @@ -974,7 +975,7 @@ private IEnumerable<CodeAttributeDeclaration> GetAttributes(bool isArray)
foreach (var derivedType in derivedTypes)
{
var derivedAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlElementAttribute), Configuration.CodeTypeReferenceOptions),
new CodeAttributeArgument(new CodePrimitiveExpression(derivedType.XmlSchemaName.Name)),
new CodeAttributeArgument(new CodePrimitiveExpression((derivedType.SubstitutionName ?? derivedType.XmlSchemaName).Name)),
new CodeAttributeArgument("Type", new CodeTypeOfExpression(derivedType.GetReferenceFor(OwningType.Namespace, false))));
if (Order != null)
{
Expand Down

0 comments on commit 3bbbd06

Please sign in to comment.