[src] Add a TransientCFString struct. by rolfbjarne · Pull Request #19763 · dotnet/macios (original) (raw)
In order to make it easier to pass C-style strings to P/Invokes, we introduced
a TransientString struct some time ago.
This works quite well, so I implemented the same for CFStrings - a
TransientCFString struct - and started using it in a few places. The idea
would be to slowly start migrating our codebase to this new pattern.
Instead of:
var ptr = CFString.CreateNative ("somestring");
try {
CallPInvoke (ptr);
} finally {
CFString.ReleaseNative (ptr);
}
we'll do:
using var ptr = new TransientCFString ("somestring");
CallPInvoke (ptr);