Skip to content

Commit

Permalink
Fix sonarcloud issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ganss committed Jul 26, 2021
1 parent 5d31527 commit 0b5f3fa
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion XmlSchemaClassGenerator/TypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public abstract class TypeModel
public List<DocumentationModel> Documentation { get; private set; }
public bool IsAnonymous { get; set; }
public GeneratorConfiguration Configuration { get; private set; }
public virtual bool IsSubtype => false;

protected TypeModel(GeneratorConfiguration configuration)
{
Expand Down Expand Up @@ -148,7 +149,7 @@ protected void GenerateTypeAttribute(CodeTypeDeclaration typeDeclaration)
var typeAttribute = new CodeAttributeDeclaration(CodeUtilities.CreateTypeReference(typeof(XmlTypeAttribute), Configuration),
new CodeAttributeArgument(new CodePrimitiveExpression(XmlSchemaName.Name)),
new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(XmlSchemaName.Namespace)));
if (IsAnonymous && (this is not ClassModel classModel || classModel.BaseClass == null))
if (IsAnonymous && !IsSubtype)
{
// don't generate AnonymousType if it's derived class, otherwise XmlSerializer will
// complain with "InvalidOperationException: Cannot include anonymous type '...'"
Expand Down Expand Up @@ -259,6 +260,8 @@ public class ClassModel : ReferenceTypeModel
public bool IsSubstitution { get; set; }
public TypeModel BaseClass { get; set; }
public List<ClassModel> DerivedTypes { get; set; }
public override bool IsSubtype => BaseClass != null;

public ClassModel(GeneratorConfiguration configuration)
: base(configuration)
{
Expand Down

0 comments on commit 0b5f3fa

Please sign in to comment.