Skip to content

Instantly share code, notes, and snippets.

@yicone
Created April 14, 2013 03:30
Show Gist options
  • Save yicone/5381314 to your computer and use it in GitHub Desktop.
Save yicone/5381314 to your computer and use it in GitHub Desktop.
My first code use MonoDevelop edit, for checking error code used situation in a project.
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
namespace CheckUnusedErrorCode
{
class MainClass
{
public static void Main (string[] args)
{
var allCodes = GetAllErrorCodes ();
var fileNames = Directory.GetFiles ("EclipseProjectFolder", "*.java", SearchOption.AllDirectories);
foreach (var code in allCodes) {
bool found = false;
foreach (var fileName in fileNames) {
int counter = 0;
string line;
using (StreamReader sr = new StreamReader(fileName)) {
while ((line = sr.ReadLine()) != null) {
if (line.Contains (code)) {
found = true;
Console.WriteLine (counter.ToString () + ": " + line);
}
counter++;
}
}
}
if (!found) {
Console.WriteLine (string.Format ("Code: {0} not found!", code));
}
}
Console.Read ();
}
private static List<string> GetAllErrorCodes ()
{
XElement root = XElement.Load ("ErrorCodes.xml");
System.Diagnostics.Debug.Assert (root != null);
var query = from e in root.Elements ()
select e.Attribute ("Code").Value;
return query.ToList ();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment