Last active
August 29, 2015 14:11
-
-
Save duncansmart/bfd4cd82f9aa41454ffe to your computer and use it in GitHub Desktop.
Creates a single source file version of DotNetZip
This file contains hidden or 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.Linq; | |
using System.Text.RegularExpressions; | |
namespace ZipReducedOneFile | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
var files = Directory.EnumerateFiles(@"C:\Temp\DotNetZip\src\Zip", "*.cs") | |
.Concat(Directory.EnumerateFiles(@"C:\Temp\DotNetZip\src\BZip2", "*.cs")) | |
.Concat(Directory.EnumerateFiles(@"C:\Temp\DotNetZip\src\Zlib", "*.cs")) | |
.Concat(Directory.EnumerateFiles(@"C:\Temp\DotNetZip\src\CommonSrc", "CRC32.cs")); | |
var lines = from file in files | |
from line in File.ReadAllLines(file) | |
select line; | |
var usingRegex = new Regex(@"^using (.+?);"); | |
var usings = (from line in lines | |
let match = usingRegex.Match(line) | |
let ns = string.Join("", match.Groups[1].Value.Where(ch => !char.IsWhiteSpace(ch))) | |
where match.Success | |
select new { line, ns }) | |
// distinct-by ns | |
.GroupBy(x => x.ns).Select(x => x.First().line); | |
var remainder = (from line in lines | |
where !usingRegex.IsMatch(line) | |
select line); | |
File.WriteAllLines( | |
@"C:\Temp\DotNetZip\src\ZipReducedOneFile\DotNetZip.cs", | |
usings.Concat(remainder)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment