Created
November 3, 2016 16:13
-
-
Save henkmollema/61fd69611a87c0d171ea7d599d471645 to your computer and use it in GitHub Desktop.
DebuggableAssemblyExtensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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