@@ -118,6 +118,7 @@ public abstract class TypeModel
118
118
public List < DocumentationModel > Documentation { get ; private set ; }
119
119
public bool IsAnonymous { get ; set ; }
120
120
public GeneratorConfiguration Configuration { get ; private set ; }
121
+ public virtual bool IsSubtype => false ;
121
122
122
123
protected TypeModel ( GeneratorConfiguration configuration )
123
124
{
@@ -148,7 +149,7 @@ protected void GenerateTypeAttribute(CodeTypeDeclaration typeDeclaration)
148
149
var typeAttribute = new CodeAttributeDeclaration ( CodeUtilities . CreateTypeReference ( typeof ( XmlTypeAttribute ) , Configuration ) ,
149
150
new CodeAttributeArgument ( new CodePrimitiveExpression ( XmlSchemaName . Name ) ) ,
150
151
new CodeAttributeArgument ( "Namespace" , new CodePrimitiveExpression ( XmlSchemaName . Namespace ) ) ) ;
151
- if ( IsAnonymous && ( this is not ClassModel classModel || classModel . BaseClass == null ) )
152
+ if ( IsAnonymous && ! IsSubtype )
152
153
{
153
154
// don't generate AnonymousType if it's derived class, otherwise XmlSerializer will
154
155
// complain with "InvalidOperationException: Cannot include anonymous type '...'"
@@ -259,6 +260,8 @@ public class ClassModel : ReferenceTypeModel
259
260
public bool IsSubstitution { get ; set ; }
260
261
public TypeModel BaseClass { get ; set ; }
261
262
public List < ClassModel > DerivedTypes { get ; set ; }
263
+ public override bool IsSubtype => BaseClass != null ;
264
+
262
265
public ClassModel ( GeneratorConfiguration configuration )
263
266
: base ( configuration )
264
267
{
0 commit comments