【问题标题】:Parser FxCop Results Xml file in C#C# 中的解析器 FxCop 结果 Xml 文件
【发布时间】:2013-01-23 10:54:15
【问题描述】:

我使用 VS2010 和 Fxcop 10.0 (fxcopcmd.exe) 以编程方式生成 fxcop 分析结果(xml 文件)

我想要 fxcop 分析结果的解析器 xml 文件。

在 java 语言中,我发现了这个: http://grepcode.com/file/repo1.maven.org/maven2/org.jvnet.hudson.plugins/violations/0.7.7/hudson/plugins/violations/types/fxcop/FxCopParser.java

对解析器 C# 有什么建议吗?

【问题讨论】:

  • 你到底想做什么?例如,我有时会使用 XSLT 来消除违规行为。
  • 我需要收集有关 fxcop 执行的信息:消息(问题 - 级别错误、警告)和异常

标签: c# xml parsing fxcop


【解决方案1】:

我使用此代码来获取报告中的问题数量。 您也可以从 XElement 检索实际消息

public class Parser
{
    public Parser(string fileName)
    {
        XDocument doc = XDocument.Load(fileName);
        var issues = GetAllIssues(doc);
        NumberOfIssues = issues.Count;

        var criticalErrors = GetCriticalErrors(issues);
        var errors = GetErrors(issues);
        var criticalWarnings = GetCriticalWarnings(issues);
        var warnings = GetWarnings(issues);

        NumberOfCriticalErrors = criticalErrors.Count;
        NumberOfErrors = errors.Count;
        NumberOfCriticalWarnings = criticalWarnings.Count;
        NumberOfWarnings = warnings.Count;
    }

    public int NumberOfIssues
    {
        get;
        private set;
    }

    public int NumberOfCriticalErrors
    {
        get;
        private set;
    }

    public int NumberOfErrors
    {
        get;
        private set;
    }

    public int NumberOfCriticalWarnings
    {
        get;
        private set;
    }

    public int NumberOfWarnings
    {
        get;
        private set;
    }

    private List<XElement> GetAllIssues(XDocument doc)
    {
        IEnumerable<XElement> issues =
            from el in doc.Descendants("Issue")
            select el;

        return issues.ToList();
    }

    private List<XElement> GetCriticalErrors(List<XElement> issues)
    {
        IEnumerable<XElement> errors = 
            from el in issues
            where (string)el.Attribute("Level") == "CriticalError"
            select el;

        return errors.ToList();
    }

    private List<XElement> GetErrors(List<XElement> issues)
    {
        IEnumerable<XElement> errors =
            from el in issues
            where (string)el.Attribute("Level") == "Error"
            select el;

        return errors.ToList();
    }

    private List<XElement> GetCriticalWarnings(List<XElement> issues)
    {
        IEnumerable<XElement> warn =
            from el in issues
            where (string)el.Attribute("Level") == "CriticalWarning"
            select el;

        return warn.ToList();
    }

    private List<XElement> GetWarnings(List<XElement> issues)
    {
        IEnumerable<XElement> warn =
            from el in issues
            where (string)el.Attribute("Level") == "Warning"
            select el;

        return warn.ToList();
    }
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-22
  • 2012-01-01
  • 2023-04-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多