Stop hiding function pointer delegate constructor #4871
Replies: 4 comments
-
That would be really great! I wrote this as a workaround: public static DelegateType CreateDelegate<DelegateType>(object target, IntPtr methodPtr)
where DelegateType : Delegate
{
var ctor = typeof(DelegateType).GetConstructor(new[] { typeof(object), typeof(IntPtr) })!;
var result = ctor.Invoke(new[] { target, methodPtr });
return (DelegateType)result;
} |
Beta Was this translation helpful? Give feedback.
-
For reference, every delegate type inherits from These types expose the following public methods:
The first is a constructor that takes the |
Beta Was this translation helpful? Give feedback.
-
If anyone would like to take the time to propose the rule changes necessary to https://github.com/dotnet/csharplang/blob/main/spec/expressions.md#delegate-creation-expressions, I'd be willing to champion the feature. |
Beta Was this translation helpful? Give feedback.
-
Possibly dup of #3680 |
Beta Was this translation helpful? Give feedback.
-
Since we now have full support for Function Pointers in C#, we should stop hiding the function pointer taking delegate constructor that exists on all delegates. This would allow some interesting delegate to function pointer mapping scenarios.
Beta Was this translation helpful? Give feedback.
All reactions