Skip to content

Commit c24c965

Browse files
authored
Merge pull request #84 from John-Welch/master
Emit XmlElementAttribute for substitutionGroups with an abstract head…
2 parents ec95c6f + 3bbbd06 commit c24c965

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

XmlSchemaClassGenerator/ModelBuilder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ public ModelBuilder(GeneratorConfiguration configuration, XmlSchemaSet set)
9696
if (type is ClassModel classModel)
9797
{
9898
classModel.Documentation.AddRange(GetDocumentation(rootElement));
99+
if (!rootElement.SubstitutionGroup.IsEmpty)
100+
{
101+
classModel.IsSubstitution = true;
102+
classModel.SubstitutionName = rootElement.QualifiedName;
103+
}
99104
}
100105

101106
type.RootElementName = rootElement.QualifiedName;

XmlSchemaClassGenerator/TypeModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ public class ClassModel : TypeModel
225225
public bool IsAbstract { get; set; }
226226
public bool IsMixed { get; set; }
227227
public bool IsSubstitution { get; set; }
228+
public XmlQualifiedName SubstitutionName { get; set; }
228229
public TypeModel BaseClass { get; set; }
229230
public List<PropertyModel> Properties { get; set; }
230231
public List<InterfaceModel> Interfaces { get; set; }
@@ -974,7 +975,7 @@ private IEnumerable<CodeAttributeDeclaration> GetAttributes(bool isArray)
974975
foreach (var derivedType in derivedTypes)
975976
{
976977
var derivedAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlElementAttribute), Configuration.CodeTypeReferenceOptions),
977-
new CodeAttributeArgument(new CodePrimitiveExpression(derivedType.XmlSchemaName.Name)),
978+
new CodeAttributeArgument(new CodePrimitiveExpression((derivedType.SubstitutionName ?? derivedType.XmlSchemaName).Name)),
978979
new CodeAttributeArgument("Type", new CodeTypeOfExpression(derivedType.GetReferenceFor(OwningType.Namespace, false))));
979980
if (Order != null)
980981
{

0 commit comments

Comments
 (0)