Skip to content

Commit

Permalink
Merge pull request #336 from StefanMaron/BugfixOnRule0027
Browse files Browse the repository at this point in the history
Resolve System.ArgumentOutOfRangeException error on LC0027
  • Loading branch information
Arthurvdv authored Nov 14, 2023
2 parents 2502245 + 9c98978 commit 83e59d6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Design/Rule0021BuiltInMethodImplementThroughCodeunit.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Microsoft.Dynamics.Nav.CodeAnalysis;
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
using System;
using Microsoft.Dynamics.Nav.CodeAnalysis.Symbols;
using System.Collections.Immutable;
using System.Linq;

namespace BusinessCentral.LinterCop.Design
{
Expand All @@ -25,11 +24,11 @@ private void CheckBuiltInMethod(OperationAnalysisContext ctx)
IInvocationExpression operation = (IInvocationExpression)ctx.Operation;
if (operation.TargetMethod.MethodKind != MethodKind.BuiltInMethod) return;

if (operation.Arguments.Count() > 1 && operation.TargetMethod.ContainingType.NavTypeKind == NavTypeKind.Page)
if (operation.TargetMethod.ContainingType.GetTypeSymbol().GetNavTypeKindSafe() == NavTypeKind.Page && operation.Arguments.Count() > 1)
{
if (operation.TargetMethod.ReturnValueSymbol.ReturnType.NavTypeKind == NavTypeKind.Action) return; // Page Management Codeunit doesn't support returntype Action
if (operation.Arguments[0].Syntax.IsKind(SyntaxKind.IdentifierName)) return; // In case the PageID is set by a field from a (setup) record, do not raise diagnostic
if (operation.TargetMethod.Name.ToUpper() == "ENQUEUEBACKGROUNDTASK") return; // do not execute on CurrPage.EnqueueBackgroundTask
if (operation.Arguments[0].Syntax.ToString().ToUpper().Substring(0, 6) != "PAGE::") return; // In case the PageID is set by a field from a (setup) record
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0027RunPageImplementPageManagement, ctx.Operation.Syntax.GetLocation()));
return;
}
Expand Down

0 comments on commit 83e59d6

Please sign in to comment.