@@ -118,6 +118,7 @@ public abstract class TypeModel
118118 public List < DocumentationModel > Documentation { get ; private set ; }
119119 public bool IsAnonymous { get ; set ; }
120120 public GeneratorConfiguration Configuration { get ; private set ; }
121+ public virtual bool IsSubtype => false ;
121122
122123 protected TypeModel ( GeneratorConfiguration configuration )
123124 {
@@ -148,7 +149,7 @@ protected void GenerateTypeAttribute(CodeTypeDeclaration typeDeclaration)
148149 var typeAttribute = new CodeAttributeDeclaration ( CodeUtilities . CreateTypeReference ( typeof ( XmlTypeAttribute ) , Configuration ) ,
149150 new CodeAttributeArgument ( new CodePrimitiveExpression ( XmlSchemaName . Name ) ) ,
150151 new CodeAttributeArgument ( "Namespace" , new CodePrimitiveExpression ( XmlSchemaName . Namespace ) ) ) ;
151- if ( IsAnonymous && ( this is not ClassModel classModel || classModel . BaseClass == null ) )
152+ if ( IsAnonymous && ! IsSubtype )
152153 {
153154 // don't generate AnonymousType if it's derived class, otherwise XmlSerializer will
154155 // complain with "InvalidOperationException: Cannot include anonymous type '...'"
@@ -259,6 +260,8 @@ public class ClassModel : ReferenceTypeModel
259260 public bool IsSubstitution { get ; set ; }
260261 public TypeModel BaseClass { get ; set ; }
261262 public List < ClassModel > DerivedTypes { get ; set ; }
263+ public override bool IsSubtype => BaseClass != null ;
264+
262265 public ClassModel ( GeneratorConfiguration configuration )
263266 : base ( configuration )
264267 {
0 commit comments