title: UnitTest to check if methods in the solution contain method-call
body: <p>In <a href="http://haacked.com/archive/2014/11/11/async-void-methods/" rel="nofollow noreferrer">this link</a> is explained why you wouldn't want to use <code>async void</code> methods and a UnitTest to track them down and avoid them. All of this works perfect using <code>reflection</code> that scans for <code>async void</code> in all the methods.</p>
  
  <p>Because we recently had a bug we want to create a similar method, which will check if there are any methods in the solution containing a <a href="http://msdn.microsoft.com/en-us/library/dd321468%28v=vs.110%29.aspx" rel="nofollow noreferrer"><code>Task#.Result</code></a> call. Unfortunately we can't access a method's body as a string and see if it contains <code>".Result;"</code> or something similar. As most of you probably know, <code>reflection</code> uses <code>metadata</code>. So we can get properties, methods, method's variable types, etc., but nothing substantial, like method's variable names or code inside a method itself.</p>
  
  <p>I know I can access the <code>MSIL</code> as a byte-aray from the methods, and I can also convert those to hexadecimal data (for example with the code found in <a href="http://dotnetcodr.com/2014/10/07/examining-the-method-body-using-reflection-in-net-c/" rel="nofollow noreferrer">this link</a>). <code>MSIL</code> is used by external libraries to make compilable and runnable C# code again (even at run-time), the problem however is that you can't read the <code>MSIL</code>.</p>
  
  <p>So, does anyone know a way to write a UnitTest that checks all methods in the solution and check if they call the get-property <code>.Result</code> on a Task. If any of these methods exist in the solution, the UnitTest should fail, if not it succeeds. (Preferably giving which methods contain this call, but this isn't a priority. If we know it fails we can search the method that calls it ourselves if needed.)</p>
  
  <p>The reason we want to avoid <code>Task#.Result</code> is because we had a deadlock. Similar to <a href="https://stackoverflow.com/questions/25896717/tolistasync-does-not-complete-at-all">this SO-post</a>.</p>