Browse Source

Quick refactoring

pull/906/head
Joe4evr 7 years ago
parent
commit
cd648ba7d0
2 changed files with 6 additions and 9 deletions
  1. +4
    -4
      src/Discord.Net.Analyzers/GuildAccessAnalyzer.cs
  2. +2
    -5
      src/Discord.Net.Analyzers/SymbolExtensions.cs

+ 4
- 4
src/Discord.Net.Analyzers/GuildAccessAnalyzer.cs View File

@@ -39,9 +39,9 @@ namespace Discord.Analyzers
return;

// Bail out if the containing class doesn't derive from 'ModuleBase<T>'
var classNode = context.Node.FirstAncestorOrSelf<TypeDeclarationSyntax>();
var classSymbol = context.SemanticModel.GetDeclaredSymbol(classNode);
if (!classSymbol.DerivesFromModuleBase())
var typeNode = context.Node.FirstAncestorOrSelf<TypeDeclarationSyntax>();
var typeSymbol = context.SemanticModel.GetDeclaredSymbol(typeNode);
if (!typeSymbol.DerivesFromModuleBase())
return;

// Bail out if the containing method isn't marked with '[Command]'
@@ -54,7 +54,7 @@ namespace Discord.Analyzers
// Is the '[RequireContext]' attribute not applied to either the
// method or the class, or its argument isn't 'ContextType.Guild'?
var ctxAttribute = methodAttributes.SingleOrDefault(_attributeDataPredicate)
?? classSymbol.GetAttributes().SingleOrDefault(_attributeDataPredicate);
?? typeSymbol.GetAttributes().SingleOrDefault(_attributeDataPredicate);

if (ctxAttribute == null || ctxAttribute.ConstructorArguments.Any(arg => !arg.Value.Equals((int)ContextType.Guild)))
{


+ 2
- 5
src/Discord.Net.Analyzers/SymbolExtensions.cs View File

@@ -8,15 +8,12 @@ namespace Discord.Analyzers
{
private static readonly string _moduleBaseName = typeof(ModuleBase<>).Name;

public static bool DerivesFromModuleBase(this INamedTypeSymbol symbol)
public static bool DerivesFromModuleBase(this ITypeSymbol symbol)
{
var bType = symbol.BaseType;
while (bType != null)
for (var bType = symbol.BaseType; bType != null; bType = bType.BaseType)
{
if (bType.MetadataName == _moduleBaseName)
return true;

bType = bType.BaseType;
}
return false;
}


Loading…
Cancel
Save