如何转换console.Output生成字符串并打印它

时间:2012-06-21 04:48:54

标签: c# nunit stylecop

我正在尝试将console.OutputGenerated转换为字符串并想要console.writeline(“打印错误”),寻求建议我如何能够这样做。下面是我的代码

public void TestMain()
    {
        string projectPath = @"C:\Documents and Settings\NickyPhun\My Documents\Visual Studio 2010\Projects\MyCustomRules3\MyCustomRules3";
        string filePath = @"C:\Documents and Settings\NickyPhun\My Documents\Visual Studio 2010\Projects\MyCustomRules3\MyCustomRules3\MyCustomRules3.cs";

        StyleCopConsole console = new StyleCopConsole(null, false, null, null, true);

        CodeProject project = new CodeProject(0, projectPath, new Configuration(null));

        console.Core.Environment.AddSourceCode(project, filePath, null);
        console.OutputGenerated += OnOutputGenerated;
        console.ViolationEncountered += OnViolationEncountered;
        console.Start(new[] { project }, true);
        console.OutputGenerated -= OnOutputGenerated;
        console.ViolationEncountered -= OnViolationEncountered;

    }

    public void OnOutputGenerated(object sender, OutputEventArgs e)
    {
        Console.WriteLine(e.Output);

    }

0 个答案:

没有答案