Last active
August 29, 2015 14:04
-
-
Save AlexArchive/b8c887bf0180da109af9 to your computer and use it in GitHub Desktop.
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
public class Counter | |
{ | |
public static int CountLines(string path) | |
{ | |
return | |
File.ReadLines(path) | |
.Count(Predicate); | |
} | |
private static bool Predicate(string line) | |
{ | |
// do not match empty lines | |
// do not match comments | |
// do not match braces | |
// ... do all of this without violating the open/closed principle | |
return true; | |
} | |
} |
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
public class Parser | |
{ | |
public static IEnumerable<string> Parse(string path) | |
{ | |
var document = XDocument.Load(path); | |
return | |
document.Descendants() | |
.Where(descendant => descendant.Name.LocalName == "Compile") | |
.Select(descendant => descendant.FirstAttribute.Value); | |
} | |
} |
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
public static class Processor | |
{ | |
public static int Process(string path) | |
{ | |
var paths = Parser.Parse(path); | |
var directoryPath = Path.GetDirectoryName(path); | |
// convert relative path to an absoloute path | |
paths = paths.Select(p => Path.Combine(directoryPath, p)); | |
return paths.Sum(p => Counter.CountLines(p)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment