title: How to create a generic type on the Action delegate with a ByRef parameter?
body: <p>I am trying to create a delegate on an Action&lt;&gt; type with a by-ref parameter as argument. But I am stuck on how to achieve this.</p>
  <p>That's what I got so far:</p>
  <pre><code>using System;
  
  class Program
  {
      struct MyStruct { }
      static void FooFn(in MyStruct s) { }
      delegate void Foo (in MyStruct s);
  
      public static void Main(string[] args)
      {
          Foo f = FooFn;
  
          var t1 = typeof(Action&lt;&gt;).MakeGenericType(typeof(MyStruct));
          var t2 = typeof(Action&lt;&gt;).MakeGenericType(typeof(MyStruct).MakeByRefType());
  
          var d = Delegate.CreateDelegate(t1, null, f.Method);
      }
  }
  </code></pre>
  <p>The issue with using &quot;t1&quot; in the delegate is, that the signature does not match. That is kindof expected, as I am passing the struct by reference.</p>
  <p>t2 does not work either, as it complains that I can not use a By-ref parameter as argument list type. :(</p>
  <p>Is there a way to create the delegate with to Foo in my example? Or do I <em>have</em> to drop the in-modifier?</p>