title: C# 7 Pattern Matching
body: <p>Suppose I have the following exception filter</p>
  
  <pre><code>try {
      ...
  } catch (Exception e) when (e is AggregateException ae &amp;&amp; ae.InnerException is ValueException&lt;int&gt; ve || e is ValueException&lt;int&gt; ve) {
      ...
  }
  </code></pre>
  
  <p>I could have simply written two separate <code>catch</code> blocks, but I wanted to see how one could use the pattern matching feature to catch an exception that either <em>is</em> itself or is wrapped within an <code>AggregateException</code>. Here, however, the compiler complains of a redefinition of <code>ve</code>, which is understandable. I have seen a case where a pattern matched variable is reused within the same expression as shown here: <a href="https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/" rel="noreferrer">https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/</a></p>
  
  <pre><code>if (o is int i || (o is string s &amp;&amp; int.TryParse(s, out i)) { /* use i */ }
  </code></pre>
  
  <p>so there is probably a way to do what I want. Or is there?</p>