コード例 #1
0
ファイル: AssemblyUtils.cs プロジェクト: Cybermaxs/IsDebug
        /// <summary>
        /// see http://dave-black.blogspot.fr/2011/12/how-to-tell-if-assembly-is-debug-or.html
        /// </summary>
        /// <param name="assembly">Assembly to test</param>
        /// <returns>IsDebugResult instance.</returns>
        public static string TryIsDebug(Assembly assembly, out IsDebugResult result)
        {
            if (assembly == null) throw new ArgumentNullException(nameof(assembly));

            result = new IsDebugResult();
            object[] attribs;
            try
            {
                attribs = assembly.GetCustomAttributes(typeof(DebuggableAttribute), false);
            }
            catch (FileNotFoundException fne)
            {
                return string.Format("Could not load {0} from . Reason : {1}", fne.FileName, assembly.FullName);
            }
            // If the 'DebuggableAttribute' is not found then it is definitely an OPTIMIZED build
            if (attribs.Length > 0)
            {
                // Just because the 'DebuggableAttribute' is found doesn't necessarily mean
                // it's a DEBUG build; we have to check the JIT Optimization flag
                // i.e. it could have the "generate PDB" checked but have JIT Optimization enabled
                var debuggableAttribute = attribs[0] as DebuggableAttribute;
                if (debuggableAttribute != null)
                {
                    result.HasDebuggableAttribute = true;
                    result.IsJITOptimized = !debuggableAttribute.IsJITOptimizerDisabled;
                    // check for Debug Output "full" or "pdb-only"
                    result.DebugOutput = (debuggableAttribute.DebuggingFlags &
                                    DebuggableAttribute.DebuggingModes.Default) !=
                                    DebuggableAttribute.DebuggingModes.None
                                    ? DebugOutputType.Full : DebugOutputType.PdbOnly;
                }
            }
            else
            {
                result.IsJITOptimized = true;
            }

            return string.Empty;
        }
コード例 #2
0
ファイル: RunnerResult.cs プロジェクト: Cybermaxs/IsDebug
 public void Ok(string assemblyPath, IsDebugResult result)
 {
     results[assemblyPath] = result;
 }