.net - Disable compiler optimisation for a specific function or block of code (C#) -


the compiler great job of optimising release builds, can useful ensure optimisation turned off local function (but not entire project unticking project options > optimize code).

in c++ achieved using following (with #pragma commented out):

#pragma optimize( "", off ) // code such function (but not whole project) #pragma optimize( "", on ) 

is there equivalent in c#?

update

several excellent answers suggest decorating method methodimploptions.nooptimization. implemented in .net 3.5, though not in compact framework (cf) version. related follow-on question whether equivalent for:

* projects targeting .net 3.0 or earlier? * projects deployed device such windows ce 6.0 using .net 3.5 cf? 

you can decorate specific method (or property getter/setter) [methodimpl(methodimploptions.nooptimization)] , [methodimpl(methodimploptions.noinlining)], prevent jitter optimizing , inlining method:

[methodimpl(methodimploptions.nooptimization | methodimploptions.noinlining)] private void methodwhichshouldnotbeoptimized() { } 

however, there isn't way apply attribute block of code. nooptimization attribute added in .net 3.5, might important legacy code or compact framework.


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

Android volley - avoid multiple requests of the same kind to the server? -

magento2 - Magento 2 admin grid add filter to collection -