我正在尝试将console.OutputGenerated 转换为字符串并想要console.writeline("print error"),寻求我如何做到这一点的建议。下面是我的代码
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);
}