I'm dealing with a WriteableBitmap in C#. I'm currently using an unsafe code block to directly access the pixels via WriteableBitmap.BackBuffer. I'd rather depend on the /unsafe option, however, so I'm considering using WriteableBitmap.WritePixels instead.
Is there some way of conditionally compiling in the "unsafe" version such that it can be used when the /unsafe option for compilation was used, without requiring manual integration into my project file?
In short I'm looking for something along the lines of:
#if UNSAFE
//my unsafe version
#else
//the supposedly safe version goes here
#endif
Detection at runtime is nice too; but that means I always need to compile with /unsafe, and that means the library code would require project file updates, which is less handy.
Basically, I want to keep the fast version for when it matters, but have a reasonable version that just works no matter what.