Skip to content

Instantly share code, notes, and snippets.

@AlbertoMonteiro
Created May 16, 2014 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlbertoMonteiro/6fcaac2def2079ae93cc to your computer and use it in GitHub Desktop.
Save AlbertoMonteiro/6fcaac2def2079ae93cc to your computer and use it in GitHub Desktop.
Capturando linhas de códido dos métodos de um Assembly
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml.Serialization;
namespace Roslyn.Console
{
class Program
{
static void Main(string[] args)
{
var process = new Process();
const string path = @"D:\Arquivos de Programa\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop\metrics.exe";
const string outputXml = @"C:\Users\Alberto\Desktop\Lines\metrics.xml";
var arguments = string.Format("/f:\"{0}\" /o:{1}", @"C:\Users\Alberto\Documents\Visual Studio 2013\Projects\Roslyn.Cobaia\Roslyn.Cobaia\bin\Debug\Roslyn.Cobaia.dll", outputXml);
process.StartInfo = new ProcessStartInfo(path,arguments);
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
var readToEnd = process.StandardOutput.ReadToEnd();
System.Console.WriteLine(readToEnd);
process.WaitForExit();
var xmlSerializer = new XmlSerializer(typeof(CodeMetricsReport));
var codeMetricsReport = (CodeMetricsReport)xmlSerializer.Deserialize(new StreamReader(outputXml));
var codeMetricsReportTargetsTarget = codeMetricsReport.Targets.Target;
System.Console.WriteLine(codeMetricsReportTargetsTarget.Name);
var module = codeMetricsReportTargetsTarget.Modules.Module;
foreach (var type in module.Namespaces.Namespace.Types)
{
System.Console.WriteLine("Classe: {0}", type.Name);
foreach (var member in type.Members)
System.Console.WriteLine("\tMétodo: {0} possui {1} linhas de código", member.Name,
member.Metrics.Last().Value);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment