Skip to content

Commit

Permalink
Added support for constructors in UseInvokeMethodToFireEventAnalyzer
Browse files Browse the repository at this point in the history
From #942.
  • Loading branch information
MaStr11 authored and giggio committed Jun 27, 2017
1 parent fe1b3ea commit 7d7391c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static void Analyzer(SyntaxNodeAnalysisContext context)

private static bool HasCheckForNullThatReturns(InvocationExpressionSyntax invocation, SemanticModel semanticModel, ISymbol symbol)
{
var method = invocation.FirstAncestorOfKind(SyntaxKind.MethodDeclaration) as MethodDeclarationSyntax;
var method = invocation.FirstAncestorOfKind(SyntaxKind.MethodDeclaration, SyntaxKind.ConstructorDeclaration) as BaseMethodDeclarationSyntax;
if (method != null && method.Body != null)
{
var ifs = method.Body.Statements.OfKind(SyntaxKind.IfStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,23 @@ public void Bar()
{
var b = _filter != null && _filter();
}
}";
await VerifyCSharpHasNoDiagnosticsAsync(test.WrapInCSharpClass());
}

[Fact]
public async void IgnoreIfInConstructorAndThatCheckedForNotNull()
{
//https://github.com/code-cracker/code-cracker/issues/926
const string test = @"
public class Foo
{
public Foo(System.Action action)
{
if (action == null)
throw new System.ArgumentNullException();
action();
}
}";
await VerifyCSharpHasNoDiagnosticsAsync(test.WrapInCSharpClass());
}
Expand Down

0 comments on commit 7d7391c

Please sign in to comment.