title: Wrap a method into a func
body: <p>I want to create a generic wrapper around Polly framework so that can have single implementation. In order to achieve it I have written below code </p>
  
  <pre><code>    private Policy GetPolicy(EType eType)
      {
          var policy = default(Polly.Policy);
  
          switch (eType)
          {                
  
              case EType.T:
                  policy = Policy.Handle&lt;SomeException&gt;().Retry(n, x =&gt; new TimeSpan(0, 0, x));
                  break;                
          }
          return policy;
      }  
  </code></pre>
  
  <p>And I am using the above method in one of my wrapper methods</p>
  
  <pre><code>   public TOutput Execute&lt;TOutput&gt;(Func&lt;TOutput&gt; func, EType eType)
      {
          var policy = GetPolicy(eType);
  
          return policy.Execute(() =&gt; func());
      }
  </code></pre>
  
  <p>Now in order to consume it I have written a sample method</p>
  
  <pre><code>       var handleError = new HandleError();
          var connection = handleError.Execute(() =&gt; factory.CreateConnection(), ExceptionType.Transient);
  </code></pre>
  
  <p>Till above all works fine, but as soon as I start calling the same in a method which takes parameter, then it throws error as </p>
  
  <pre><code>     var handleError = new HandleError();
          handleError.Execute(() =&gt; channel.ExchangeDeclare(queueDetail.ExchangeName, ExchangeType.Fanout), ExceptionType.Transient);
  
       The type arguments for method 'HandleError.Execute&lt;TOutput&gt;(Func&lt;TOutput&gt;, ExceptionType)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
  </code></pre>