Last active
August 29, 2015 14:04
-
-
Save alexdresko/5b3075d12a9b5abebb4c to your computer and use it in GitHub Desktop.
Create POCO and CsvHelper map classes from pipe delimited file.linq
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
void Main() | |
{ | |
var dir = @"C:\temp\OptumFtp\Root\Extracted\"; | |
foreach (var file in Directory.GetFiles(dir, "*.txt")) | |
{ | |
var header = File.ReadAllLines(file)[0]; | |
var map = Regex.Replace(header, @"([^|]*).", @"Map(m => m.$1).Name(""$1""); | |
"); | |
var properties = Regex.Replace(header, @"([^|]*).", @"public string $1 { get; set; } | |
"); | |
var filename = Path.GetFileNameWithoutExtension(file); | |
string.Format(@" | |
public class {0} | |
{{ | |
{1} | |
}}", filename, properties).Dump(); | |
string.Format(@" | |
public class {0}Map : CsvClassMap<{0}> | |
{{ | |
public {0}Map() | |
{{ | |
{1} | |
}} | |
}}", filename, map).Dump(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment