Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to tell if a C# assembly has been compiled with the optimization parameter?

Rather, is there a way to tell if it's been compiled with the optimization parameter enabled or disabled. I don't want to know if it's release or debug, since either can be enabled with or without optimizations. From my perspective, even though the code says it's release version, is it truly optimized? Thanks.

like image 629
John Avatar asked Aug 20 '10 18:08

John


People also ask

What to do if AC is running but not cooling?

To troubleshoot the issue, check the condenser and clean away any debris. This area can be cleaned by a vacuum with a brush attachment, or try using a hose to gently wipe away any dirt and grime. Still dealing with AC running but not cooling? If so, it may be time to call a professional for service.


1 Answers

I'm 8 years late but if you, like me, wanted a C# way, here it is:

using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;

internal static class AssemblyExtensions
{
    public static bool IsOptimized(this Assembly asm)
    {
        var att = asm.GetCustomAttribute<DebuggableAttribute>();
        return att == null || att.IsJITOptimizerDisabled == false;
    }
}

As an extension method:

static void Main(string[] args)
{
    Console.WriteLine("Is optmized: " + typeof(Program).Assembly.IsOptimized());
}
like image 76
Bruno Garcia Avatar answered Sep 28 '22 05:09

Bruno Garcia