Method TryGet
- Namespace
- Ubiquity.NET.InteropHelpers
- Assembly
- Ubiquity.NET.InteropHelpers.dll
TryGet<T>(void*, out T)
public static bool TryGet<T>(void* ctx, out T value)
Parameters
Returns
Type Parameters
T
Type of object the context should hold
Remarks
This assumes that ctx
is a GCHandle that was allocated and provided to native code via
a call to ToIntPtr(GCHandle). This will follow the try pattern to resolve ctx
back to the original instance the handle is referencing. This allows managed code callbacks to use managed objects as
an opaque "context" value for native APIs.
important
In order to satisfy nullability code analysis, call sites must declare T
explicitly. Otherwise,
it is deduced as the type used for value
, which will cause analysis to complain if it isn't a nullable type.
Thus, without explicit declaration of the type without nullability it is assumed nullable and the MaybeNullWhenAttribute
is effectively moot. So call sites should always specify the generic type parameter T
explicitly.