Skip to content

Instantly share code, notes, and snippets.

@bruno-garcia
Last active April 14, 2018 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruno-garcia/4443962b586eef8916a8644db21fc724 to your computer and use it in GitHub Desktop.
Save bruno-garcia/4443962b586eef8916a8644db21fc724 to your computer and use it in GitHub Desktop.
Is .NET assembly optimized
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class AssemblyExtensions
{
/// <summary>
/// Whether the assembly was compiled with the optimize+ flag
/// </summary>
/// <param name="asm">The assemlby to verify the optimization flag</param>
/// <returns>
/// true if no <see cref="DebuggableAttribute"/> exists or
/// <see cref="DebuggableAttribute.IsJITOptimizerDisabled"/> is false,
/// otherwise, false.
/// </returns>
public static bool IsOptimized(this Assembly asm)
{
var att = asm.GetCustomAttribute<DebuggableAttribute>();
return att == null || att.IsJITOptimizerDisabled == false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment