Created
April 14, 2013 03:30
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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