-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use generic Marshal.StructureToPtr #6044
Use generic Marshal.StructureToPtr #6044
Conversation
@@ -38,7 +38,8 @@ override protected bool ReleaseHandle() | |||
} | |||
|
|||
// uiaCondition is one of the Uia condition structs - eg UiaCoreApi.UiaAndOrCondition | |||
internal static SafeConditionMemoryHandle AllocateConditionHandle(object uiaCondition) | |||
internal static SafeConditionMemoryHandle AllocateConditionHandle<T>(T uiaCondition) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using generics here allows to call the generic version of Marshal.StructureToPtr and also to avoid boxing of uiaCondition
. Every call to AllocateConditionHandle
passes a struct for uiaCondition
.
Thank you! |
caff652
to
f627e90
Compare
Hey all, any comment on this PR from the repo / code owners would be appreciated. The PR has been open for two months and it looks like a minor change that is not breaking anything. CC @SamBent / @fabiant3 / @vishalmsft / @singhashish-wpf Context: .NET Core 3.1 is EoL at the end of the year. Trimming is unstable and practically unusable in production with any subsequent .NET versions. There has been little to no progress on #3811 with duplicates being closed with no comment regarding the original issue. |
Description
Use generic Marshal.StructureToPtr instead of the non-generic. I removed the customs UnsafeNativeMethods.StructureToPtr which justs forwards to Marshal.StructureToPtr because it causes linker warnings because Marshal.StructureToPtr is annotated while UnsafeNativeMethods.StructureToPtr isn't.
Almost every call to Marshal.StructureToPtr were already using the generic overload without the need to change the code.
Contributes to #3811
Customer Impact
None, same behavior as the non-generic.
Regression
No
Testing
I manually tested a few of the generic and non-generic and they gave the same result.
Risk
None, same behavior as the non-generic.