-
Notifications
You must be signed in to change notification settings - Fork 357
Closed
Labels
feature request 📬A request for new changes to improve functionalityA request for new changes to improve functionalityhigh-performance 🚂Issues/PRs for the HighPerformance packageIssues/PRs for the HighPerformance package
Description
The existing DangerousGetValueOrDefaultReference()
is useful, but for a lot of my interop code I need null
when HasValue
is false
I'm actually using a more dangerous version in my code base that returns a pointer, but @Sergio0694 says return a null ref
is a better idea, and I agree. Can always Unsafe.AsPointer()
from that.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe ref T DangerousGetValueOrNullReference<T>(ref this T? maybe)
where T : unmanaged
{
return ref (maybe.HasValue ? ref maybe.DangerousGetValueOrDefaultReference() : ref Unsafe.NullRef<T>());
}
Metadata
Metadata
Assignees
Labels
feature request 📬A request for new changes to improve functionalityA request for new changes to improve functionalityhigh-performance 🚂Issues/PRs for the HighPerformance packageIssues/PRs for the HighPerformance package