8000 [Mvc] Avoid exception in route analyzer by martincostello · Pull Request #63033 · dotnet/aspnetcore · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Shared/Roslyn/MvcFacts.cs
8000
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public static bool IsControllerAction(IMethodSymbol method, INamedTypeSymbol non
}

// Overridden methods from Object class, e.g. Equals(Object), GetHashCode(), etc., are not valid.
if (GetDeclaringType(method).SpecialType == SpecialType.System_Object)
var declaringType = GetDeclaringType(method);
if (declaringType == null || declaringType.SpecialType == SpecialType.System_Object)
{
return false;
}
Expand Down Expand Up @@ -98,13 +99,13 @@ public static bool IsControllerAction(IMethodSymbol method, INamedTypeSymbol non
return method.DeclaredAccessibility == Accessibility.Public;
}

private static INamedTypeSymbol GetDeclaringType(IMethodSymbol method)
private static INamedTypeSymbol? GetDeclaringType(IMethodSymbol method)
{
while (method.IsOverride)
{
if (method.OverriddenMethod == null)
{
throw new InvalidOperationException($"{nameof(method.OverriddenMethod)} cannot be null.");
return null;
}

method = method.OverriddenMethod;
Expand Down
Loading
0