title: Number of occurrences of a method NDepend
body: <p>I need to write an NDepend rule that checks if every await of an Async Method uses ConfigureAwait(false).</p>
  
  <p>I check if a method uses ConfigureAwait(Boolean). If that method doesn't use it, it has violated the rule.</p>
  
  <pre><code>from m in JustMyCode.Methods 
  where
  !(m.IsUsingMethod("System.Threading.Tasks.Task.ConfigureAwait(Boolean)") ||
  m.IsUsingMethod("System.Threading.Tasks.Task&lt;TResult&gt;.ConfigureAwait(Boolean)")) &amp;&amp; 
  m.IsAsync
  
  select new { 
   m,
   m.MethodsCalled
  }
  </code></pre>
  
  <p>This code works fine if you are sure that every async method uses one await.
  But what if a method uses two awaits? then you could count all occurrences of await in that method.</p>
  
  <p><strong>Example</strong> </p>
  
  <pre><code>public async Task Foo()
  {
    await DoSomething();
  }
  
  public async Task Bar()
  {
    await DoSomething().ConfigureAwait(false);
  }
  
  public async Task Stone()
  {
    await DoSomething();
    await DoSomething().ConfigureAwait(false);
  }
  </code></pre>
  
  <p>Foo and Stone Has violated the rule.</p>
  
  <p>With my code I can see that Foo has violated the rule, but Stone hasn't violated It.</p>
  
  <p>With 'MethodsCalled' I am able to check if a method uses ConfigureAwait(), which is nice. But again I am not able to check how many occurrences of await and ConfigureAwait() 'Stone' has. </p>