我正在尝试将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);
}