提交 e0ad6f4f 编写于 作者: M Manish Vasani

Merge pull request #11001 from mavasani/Issue10314

Fix the "Unused parameter" sample analyzers to ignore compiler genera…
......@@ -78,8 +78,9 @@ private class UnusedParametersAnalyzer
public UnusedParametersAnalyzer(IMethodSymbol method)
{
// Initialization: Assume all parameters are unused.
_unusedParameters = new HashSet<IParameterSymbol>(method.Parameters);
_unusedParameterNames = new HashSet<string>(method.Parameters.Select(p => p.Name));
var parameters = method.Parameters.Where(p => !p.IsImplicitlyDeclared);
_unusedParameters = new HashSet<IParameterSymbol>(parameters);
_unusedParameterNames = new HashSet<string>(parameters.Select(p => p.Name));
}
#endregion
......
......@@ -46,8 +46,8 @@ private static void CodeBlockAction(CodeBlockAnalysisContext codeBlockContext)
// Report diagnostic for void non-virtual methods with empty method bodies.
var method = (IMethodSymbol)codeBlockContext.OwningSymbol;
var block = (BlockSyntax)codeBlockContext.CodeBlock.ChildNodes().First(n => n.Kind() == SyntaxKind.Block);
if (method.ReturnsVoid && !method.IsVirtual && block.Statements.Count == 0)
var block = (BlockSyntax)codeBlockContext.CodeBlock.ChildNodes().FirstOrDefault(n => n.Kind() == SyntaxKind.Block);
if (method.ReturnsVoid && !method.IsVirtual && block != null && block.Statements.Count == 0)
{
var tree = block.SyntaxTree;
var location = method.Locations.First(l => tree.Equals(l.SourceTree));
......
......@@ -67,8 +67,9 @@ Namespace BasicAnalyzers
#Region "State intialization"
Public Sub New(method As IMethodSymbol)
' Initialization: Assume all parameters are unused.
_unusedParameters = New HashSet(Of IParameterSymbol)(method.Parameters)
_unusedParameterNames = New HashSet(Of String)(method.Parameters.Select(Function(p) p.Name))
Dim parameters = method.Parameters.Where(Function(p) Not p.IsImplicitlyDeclared)
_unusedParameters = New HashSet(Of IParameterSymbol)(parameters)
_unusedParameterNames = New HashSet(Of String)(parameters.Select(Function(p) p.Name))
End Sub
#End Region
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册