2012-12-12 415 views
0

我有VS2010中,Windows 7位,FxCop的10.0513錯誤代碼(退出代碼)的FxCop使用C#

我執行使用的Process.Start Fxcopcmd.exe,我也得到513 「退出碼」(錯誤代碼)值。

託德·金在下面引用說:

在這種情況下,513的退出代碼指的FxCop有一個分析錯誤 (0×01)和裝配引用錯誤(在0x200)

http://social.msdn.microsoft.com/Forums/en-US/vstscode/thread/1191af28-d262-4e4f-95d9-73b682c2044c/

我想,如果它像

[Flags] 
    public enum FxCopErrorCodes 
    { 
     NoErrors = 0x0, 
     AnalysisError = 0x1, // -fatalerror 
     RuleExceptions = 0x2, 
     ProjectLoadError = 0x4, 
     AssemblyLoadError = 0x8, 
     RuleLibraryLoadError = 0x10, 
     ImportReportLoadError = 0x20, 
     OutputError = 0x40, 
     CommandlineSwitchError = 0x80, 
     InitializationError = 0x100, 
     AssemblyReferencesError = 0x200, 
     BuildBreakingMessage = 0x400, 
     UnknownError = 0x1000000, 
    } 

513的整數值是0x201(查看int to hex stringEnum.Parse fails to cast string

我怎麼能知道錯誤(錯誤分析(0×01)和裝配引用錯誤(在0x200))以編程方式使用唯一的退出碼(513,0x201)值?

更多關於FxCopCmd和代碼分析錯誤代碼:

+0

也許有用http://stackoverflow.com/a/5655038/206730 – Kiquenet

回答

0

您可以使用AND位運算測試你的枚舉的特定值:

FxCopErrorCodes code = (FxCopErrorCodes)0x201; 
if ((code & FxCopErrorCodes.InitializationError) == FxCopErrorCodes.InitializationError) 
{ 
    Console.WriteLine("InitializationError"); 
} 

你可以得到整個列表使用類似的值:

private static IEnumerable<FxCopErrorCodes> GetMatchingValues(FxCopErrorCodes enumValue) 
{ 
    // Special case for 0, as it always match using the bitwise AND operation 
    if (enumValue == 0) 
    { 
     yield return FxCopErrorCodes.NoErrors; 
    } 

    // Gets list of possible values for the enum 
    var values = Enum.GetValues(typeof(FxCopErrorCodes)).Cast<FxCopErrorCodes>(); 

    // Iterates over values and return those that match 
    foreach (var value in values) 
    { 
     if (value > 0 && (enumValue & value) == value) 
     { 
      yield return value; 
     } 
    } 
} 
+1

@Kiquenet它適用於3.5及以上版本。你必須添加'使用System.Linq;'。請參閱http://msdn.microsoft.com/en-us/library/bb341406(v=vs.90).aspx – ken2k