首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C#格式的解析器FxCop结果Xml文件

C#格式的解析器FxCop结果Xml文件
EN

Stack Overflow用户
提问于 2013-01-23 18:54:16
回答 1查看 643关注 0票数 2

我编程地使用VS2010和FxCop10.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#有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2014-03-13 16:04:38

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

代码语言:javascript
复制
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();
    }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14477933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档