Skip to content

Instantly share code, notes, and snippets.

@henkmollema
Created November 3, 2016 16:13
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 henkmollema/61fd69611a87c0d171ea7d599d471645 to your computer and use it in GitHub Desktop.
Save henkmollema/61fd69611a87c0d171ea7d599d471645 to your computer and use it in GitHub Desktop.
DebuggableAssemblyExtensions
using System.Diagnostics;
using System.Reflection;
namespace Novusoft.Fms.Templates
{
public static class DebuggableAssemblyExtensions
{
private static readonly FieldInfo _debuggingModeField = typeof(DebuggableAttribute).GetField("m_debuggingModes", BindingFlags.NonPublic | BindingFlags.Instance);
/// <summary>
/// Determines whether debugging mode is enabled in the specified assembly.
/// </summary>
public static bool IsAssemblyDebuggingEnabled(this Assembly assembly)
{
// HACK: this is a temporary workaround for the absence of the public properties on DebuggableAttribute.
// These will be added in .NET Standard 2.0.
var debuggableAttribute = assembly.GetCustomAttribute<DebuggableAttribute>();
if (debuggableAttribute == null)
{
// No DebuggableAttribute implies that JIT debugging is disabled.
return true;
}
var debuggingModes = (DebuggableAttribute.DebuggingModes)_debuggingModeField.GetValue(debuggableAttribute);
return (debuggingModes & DebuggableAttribute.DebuggingModes.Default) != 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment