-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb50ed5
commit 5b0b5a5
Showing
8 changed files
with
193 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Immediate.Apis.Analyzers; | ||
|
||
internal static class ITypeSymbolExtensions | ||
{ | ||
public static bool IsImmediateApisShared(this INamespaceSymbol symbol) => | ||
symbol is | ||
{ | ||
Name: "Shared", | ||
ContainingNamespace: | ||
{ | ||
Name: "Apis", | ||
ContainingNamespace: | ||
{ | ||
Name: "Immediate", | ||
ContainingNamespace.IsGlobalNamespace: true, | ||
}, | ||
}, | ||
}; | ||
|
||
public static bool IsMapMethodAttribute(this ITypeSymbol? typeSymbol, string method) => | ||
typeSymbol?.Name == $"Map{method}Attribute" | ||
&& typeSymbol.ContainingNamespace.IsImmediateApisShared(); | ||
|
||
private static readonly string[] s_methods = ["Get", "Post", "Put", "Patch", "Delete"]; | ||
public static bool IsMapMethodAttribute(this ITypeSymbol? typeSymbol) => | ||
s_methods.Any(typeSymbol.IsMapMethodAttribute); | ||
|
||
public static bool IsMicrosoftAspNetCoreAuthorization(this INamespaceSymbol symbol) => | ||
symbol is | ||
{ | ||
Name: "Authorization", | ||
ContainingNamespace: | ||
{ | ||
Name: "AspNetCore", | ||
ContainingNamespace: | ||
{ | ||
Name: "Microsoft", | ||
ContainingNamespace.IsGlobalNamespace: true, | ||
}, | ||
}, | ||
}; | ||
|
||
public static bool IsAllowAnonymous(this ITypeSymbol? typeSymbol) => | ||
typeSymbol?.Name is "AllowAnonymousAttribute" | ||
&& typeSymbol.ContainingNamespace.IsMicrosoftAspNetCoreAuthorization(); | ||
|
||
public static bool IsAuthorize(this ITypeSymbol? typeSymbol) => | ||
typeSymbol?.Name is "AuthorizeAttribute" | ||
&& typeSymbol.ContainingNamespace.IsMicrosoftAspNetCoreAuthorization(); | ||
|
||
public static bool IsHandlerAttribute(this ITypeSymbol? typeSymbol) => | ||
typeSymbol is | ||
{ | ||
Name: "HandlerAttribute", | ||
ContainingNamespace: | ||
{ | ||
Name: "Shared", | ||
ContainingNamespace: | ||
{ | ||
Name: "Handlers", | ||
ContainingNamespace: | ||
{ | ||
Name: "Immediate", | ||
ContainingNamespace.IsGlobalNamespace: true, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
public static bool IsIEndpointConventionBuilder(this ITypeSymbol? typeSymbol) => | ||
// IErrorTypeSymbol is until we can reference AspNetCore framework | ||
typeSymbol is IErrorTypeSymbol or | ||
{ | ||
Name: "IEndpointConventionBuilder", | ||
ContainingNamespace: | ||
{ | ||
Name: "Builder", | ||
ContainingNamespace: | ||
{ | ||
Name: "AspNetCore", | ||
ContainingNamespace: | ||
{ | ||
Name: "Microsoft", | ||
ContainingNamespace.IsGlobalNamespace: true, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Immediate.Apis.Generators; | ||
|
||
internal static class ITypeSymbolExtensions | ||
{ | ||
public static bool IsImmediateApisShared(this INamespaceSymbol symbol) => | ||
symbol is | ||
{ | ||
Name: "Shared", | ||
ContainingNamespace: | ||
{ | ||
Name: "Apis", | ||
ContainingNamespace: | ||
{ | ||
Name: "Immediate", | ||
ContainingNamespace.IsGlobalNamespace: true, | ||
}, | ||
}, | ||
}; | ||
|
||
public static bool IsMapMethodAttribute(this ITypeSymbol? typeSymbol, string method) => | ||
typeSymbol?.Name == $"Map{method}Attribute" | ||
&& typeSymbol.ContainingNamespace.IsImmediateApisShared(); | ||
|
||
public static bool IsMicrosoftAspNetCoreAuthorization(this INamespaceSymbol symbol) => | ||
symbol is | ||
{ | ||
Name: "Authorization", | ||
ContainingNamespace: | ||
{ | ||
Name: "AspNetCore", | ||
ContainingNamespace: | ||
{ | ||
Name: "Microsoft", | ||
ContainingNamespace.IsGlobalNamespace: true, | ||
}, | ||
}, | ||
}; | ||
|
||
public static bool IsAllowAnonymous(this ITypeSymbol? typeSymbol) => | ||
typeSymbol?.Name is "AllowAnonymousAttribute" | ||
&& typeSymbol.ContainingNamespace.IsMicrosoftAspNetCoreAuthorization(); | ||
|
||
public static bool IsAuthorize(this ITypeSymbol? typeSymbol) => | ||
typeSymbol?.Name is "AuthorizeAttribute" | ||
&& typeSymbol.ContainingNamespace.IsMicrosoftAspNetCoreAuthorization(); | ||
|
||
public static bool IsIEndpointConventionBuilder(this ITypeSymbol? typeSymbol) => | ||
// IErrorTypeSymbol is until we can reference AspNetCore framework | ||
typeSymbol is IErrorTypeSymbol or | ||
{ | ||
Name: "IEndpointConventionBuilder", | ||
ContainingNamespace: | ||
{ | ||
Name: "Builder", | ||
ContainingNamespace: | ||
{ | ||
Name: "AspNetCore", | ||
ContainingNamespace: | ||
{ | ||
Name: "Microsoft", | ||
ContainingNamespace.IsGlobalNamespace: true, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters