AssemblyCheckTool是一个用于读取检查.NET程序或程序集编译状态的小工具,其原理是通过反射读取Assembly信息,并判断DebuggableAttribute属性值来完成的,核心部分代码如下:
/// <summary>
/// 判断是否为Debug模式
/// Author:ppchen
/// </summary>
private static bool IsAssemblyDebugBuild(string filepath)
{
return IsAssemblyDebugBuild(Assembly.LoadFile(Path.GetFullPath(filepath)));
}
private static bool IsAssemblyDebugBuild(Assembly asm)
{
object[] objs = asm.GetCustomAttributes(typeof(System.Diagnostics.DebuggableAttribute), true);
if (objs.Length > 0)
{
DebuggableAttribute debugAtt = objs[0] as DebuggableAttribute;
if (debugAtt != null)
{
return debugAtt.IsJITTrackingEnabled;
}
}
return false;
}
/// 判断是否为Debug模式
/// Author:ppchen
/// </summary>
private static bool IsAssemblyDebugBuild(string filepath)
{
return IsAssemblyDebugBuild(Assembly.LoadFile(Path.GetFullPath(filepath)));
}
private static bool IsAssemblyDebugBuild(Assembly asm)
{
object[] objs = asm.GetCustomAttributes(typeof(System.Diagnostics.DebuggableAttribute), true);
if (objs.Length > 0)
{
DebuggableAttribute debugAtt = objs[0] as DebuggableAttribute;
if (debugAtt != null)
{
return debugAtt.IsJITTrackingEnabled;
}
}
return false;
}
上一个程序的截图:
程序下载:
AssemblyCheckTool