Skip to content

Instantly share code, notes, and snippets.

@alexdresko
Last active August 29, 2015 14:04
Show Gist options
  • Save alexdresko/5b3075d12a9b5abebb4c to your computer and use it in GitHub Desktop.
Save alexdresko/5b3075d12a9b5abebb4c to your computer and use it in GitHub Desktop.
Create POCO and CsvHelper map classes from pipe delimited file.linq
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