diff --git a/Design/Rule0032ClearCodeunitSingleInstance.cs b/Design/Rule0032ClearCodeunitSingleInstance.cs index 056652f1..9733ba0b 100644 --- a/Design/Rule0032ClearCodeunitSingleInstance.cs +++ b/Design/Rule0032ClearCodeunitSingleInstance.cs @@ -46,11 +46,13 @@ private void ClearAllCodeunit(OperationAnalysisContext ctx) if (!SemanticFacts.IsSameName(operation.TargetMethod.Name, "ClearAll")) return; IEnumerable localVariables = ((IMethodSymbol)ctx.ContainingSymbol.OriginalDefinition).LocalVariables - .Where(var => var.OriginalDefinition.GetTypeSymbol().GetNavTypeKindSafe() == NavTypeKind.Codeunit); + .Where(var => var.OriginalDefinition.GetTypeSymbol().GetNavTypeKindSafe() == NavTypeKind.Codeunit) + .Where(var => var.OriginalDefinition.GetTypeSymbol().OriginalDefinition != ctx.ContainingSymbol.GetContainingObjectTypeSymbol().OriginalDefinition); IEnumerable globalVariables = ctx.ContainingSymbol.GetContainingObjectTypeSymbol() .GetMembers() .Where(members => members.Kind == SymbolKind.GlobalVariable) - .Where(var => var.OriginalDefinition.GetTypeSymbol().GetNavTypeKindSafe() == NavTypeKind.Codeunit); + .Where(var => var.OriginalDefinition.GetTypeSymbol().GetNavTypeKindSafe() == NavTypeKind.Codeunit) + .Where(var => var.OriginalDefinition.GetTypeSymbol().OriginalDefinition != ctx.ContainingSymbol.GetContainingObjectTypeSymbol().OriginalDefinition); if (HasSingleInstanceCodeunitWithGlobalVars(localVariables, out ISymbol codeunit) || HasSingleInstanceCodeunitWithGlobalVars(globalVariables, out codeunit)) ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0032ClearCodeunitSingleInstance, ctx.Operation.Syntax.GetLocation(), new Object[] { codeunit.Name, codeunit.GetTypeSymbol().Name }));