Add CreateDelegatePointer for PROC and FARPROC
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.5k
- Forks
- 124
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 9
Description
Is your feature request related to a problem? Please describe.
For now, we have CreateDelegate to create delegate from PROC and FARPROC. But when the delegate has generated to a struct for delegate*, it cannot work.
Describe the solution you'd like
Add a CreateDelegatePointer method for PROC and FARPROC, such as:
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal TDelegate CreateDelegatePointer<TDelegate>() where T : unmanaged => Unsafe.As<PROC, T>(ref this.Value);
Describe alternatives you've considered
For now, we can create an extension to use it:
JClass mainClass = env->functions->FindClass.CreateDelegatePointer<FindClass>().Value(env, "java/lang/String"u8.AsPCSTR());
file static class Extensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static PCSTR AsPCSTR(this scoped in ReadOnlySpan<byte> data) => Unsafe.As<ReadOnlySpan<byte>, PCSTR>(ref Unsafe.AsRef(in data));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TDelegate CreateDelegatePointer<TDelegate>(this PROC function) where T : unmanaged => Unsafe.As<PROC, T>(ref function);
}
Additional context
#1629
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the existing CreateDelegate implementations for PROC and FARPROC and inspect how their supporting types are generated. Add the corresponding pointer-delegate entry points, then verify the delegate* struct scenario described in the issue and the existing usage pattern from #1629.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- devtools, operating-systems
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100