Skip to content

Commit 06d874f

Browse files
committed
Improve performance
1 parent c38a11e commit 06d874f

4 files changed

Lines changed: 24 additions & 2 deletions

File tree

csharp/ql/lib/semmle/code/csharp/frameworks/microsoft/AspNetCore.qll

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,21 @@ private predicate isDefaultMicrosoftAspNetCoreMvcController(Class controller) {
388388
MicrosoftAspNetCoreMvcNonControllerAttribute
389389
}
390390

391+
private predicate isMicrosoftAspNetCoreMvcIDisposableMethod(Method method) {
392+
exists(Method baseMethod |
393+
baseMethod = method.getOverridee*() and
394+
not exists(baseMethod.getOverridee()) and
395+
(
396+
baseMethod.getExplicitlyImplementedInterface() instanceof SystemIDisposableInterface
397+
or
398+
baseMethod.getUndecoratedName() = "Dispose" and
399+
baseMethod.getNumberOfParameters() = 0 and
400+
baseMethod.getReturnType() instanceof VoidType and
401+
baseMethod.getDeclaringType().getABaseInterface*() instanceof SystemIDisposableInterface
402+
)
403+
)
404+
}
405+
391406
/** A class treated as an owner of ASP.NET Core MVC controller helper methods. */
392407
class MicrosoftAspNetCoreMvcControllerHelperClass extends Class {
393408
MicrosoftAspNetCoreMvcControllerHelperClass() {
@@ -424,10 +439,10 @@ class MicrosoftAspNetCoreMvcController extends Class {
424439
result.isPublic() and
425440
not result.isStatic() and
426441
not result.isAbstract() and
427-
not result.getUnboundDeclaration() instanceof UnboundGenericMethod and
442+
not result instanceof Generic and
428443
not result.getOverridee*().getAnAttribute() instanceof MicrosoftAspNetCoreMvcNonActionAttribute and
429444
not result.getOverridee*().getDeclaringType() instanceof ObjectType and
430-
not result instanceof DisposeMethod
445+
not isMicrosoftAspNetCoreMvcIDisposableMethod(result)
431446
}
432447

433448
/** Gets a `Redirect*`, `Accepted*`, or `Created*` method. */

csharp/ql/test/library-tests/frameworks/microsoft/AspNetCore.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,8 @@ internal void InternalAction(string input) { }
196196

197197
private void PrivateAction(string input) { }
198198
}
199+
200+
public class NewDisposeController : Controller
201+
{
202+
public new void Dispose() { }
203+
}

csharp/ql/test/library-tests/frameworks/microsoft/AspNetCore.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
| AspNetCore.cs:155:14:155:36 | ClosedGenericController |
1111
| AspNetCore.cs:171:14:171:35 | ConcreteActionEndpoint |
1212
| AspNetCore.cs:178:14:178:34 | ActionCasesController |
13+
| AspNetCore.cs:200:14:200:33 | NewDisposeController |

csharp/ql/test/library-tests/frameworks/microsoft/AspNetCoreActions.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
| AspNetCore.cs:171:14:171:35 | ConcreteActionEndpoint | AspNetCore.cs:165:17:165:31 | InheritedAction |
1414
| AspNetCore.cs:171:14:171:35 | ConcreteActionEndpoint | AspNetCore.cs:173:26:173:39 | AbstractAction |
1515
| AspNetCore.cs:178:14:178:34 | ActionCasesController | AspNetCore.cs:180:17:180:28 | PublicAction |
16+
| AspNetCore.cs:200:14:200:33 | NewDisposeController | AspNetCore.cs:202:21:202:27 | Dispose |

0 commit comments

Comments
 (0)