38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
namespace wvdet.CodeChecker
|
|
{
|
|
public class CheckNamespace : ICheckable
|
|
{
|
|
private static List<string> Forbiddens = new List<string>()
|
|
{
|
|
//针对于禁用的命名空间放在此处
|
|
// "System.Linq",
|
|
|
|
};
|
|
|
|
public List<Detail> Check(string filepath, CompilationUnitSyntax root)
|
|
{
|
|
var results = new List<Detail>();
|
|
|
|
var usings = root.DescendantNodes().OfType<UsingDirectiveSyntax>();
|
|
foreach (var us in usings)
|
|
{
|
|
var ns = us.Name.ToString();
|
|
if (Forbiddens.Contains(ns))
|
|
{
|
|
results.Add(new Detail
|
|
{
|
|
level = Level.Error,
|
|
line = us.GetLocation().GetLineSpan().StartLinePosition.Line + 1,
|
|
guideline = $"禁用此命名空间:{ns}",
|
|
});
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
}
|
|
} |