Skip to content

Commit 0b5f3fa

Browse files
author
Michael Ganss
committed
Fix sonarcloud issue
1 parent 5d31527 commit 0b5f3fa

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

XmlSchemaClassGenerator/TypeModel.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)