Skip to content

Commit

Permalink
Rule LC0032 should not be raised when codeunit is used in itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthurvdv committed Nov 20, 2023
1 parent 24b5192 commit e38c7ad
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Design/Rule0032ClearCodeunitSingleInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ private void ClearAllCodeunit(OperationAnalysisContext ctx)
if (!SemanticFacts.IsSameName(operation.TargetMethod.Name, "ClearAll")) return;

IEnumerable<ISymbol> 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<ISymbol> 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 }));
Expand Down

0 comments on commit e38c7ad

Please sign in to comment.