You can declare an unsafe member of type RuntimeDescriptor*
. And you can declare the return value of your p/invoke to be of type RuntimeDescriptor*
.
However, it doesn't really gain you any performance over a cast to RuntimeDescriptor*
. Certainly with optimisations enabled, the compiler doesn't need to emit any actual code to perform the cast. However, if you are going down the route of using unsafe code then it's cleaner to be all-in. Declaring the member and return type to be RuntimeDescriptor*
makes your program easier to read.
FWIW, there's no need for the call ToPointer()
in the code in your question. You can write that cast like this:
(RuntimeDescriptor*)pointerField