   [.net] suppressing method inlining
  Is there anyway in code (presume C#) to prevent the .NET JIT from inlining method calls? I have an Object-Relational mapping system that constructs ADO.NET stored procedure calls dynamically by walking the stack trace to find an upstream method that has a flagging attribute attached to it. These methods are very small because all they do is call the dynamic SP builder. If I'm calling the method directly from client code, it executes fine. If the method is called from within another method in the data access layer, it gets inlined in the larger method, which makes it lose the custom attribute. If I turn off optimizations, it works fine, but I'm afraid some chucklehead is going to decide to turn optimizations on when I'm not looking. Ideally, if it were something I could attach to my attribute, that'd be great.   
  Maybe look into internal and possibly protected internal, it would need to be in a different assembly and I'm not sure it would work to be honest :)link;Here I found a list of conditions which must be met for method to be inlined. But it's pretty old (from 2004) so it could have changed since then. I don't know of any NoInlineAttribute or something like that.   ;  You can use MethodImplAttribute, like so:[MethodImpl(MethodImplOptions.NoInlining)]void Blah(){};  You can also derive from MarshalByRefObject: "Enables access to objects across application domain boundaries in applications that support remoting."This may or may not apply to your design, but it sure turns off inlining for the derived object.   ;Quote:Original post by CodekaYou can use MethodImplAttribute, like so:[MethodImpl(MethodImplOptions.NoInlining)]void Blah(){}This looks exactly like what I want. Thanks.   