Last active
October 6, 2016 16:10
-
-
Save airbreather/71a72a0bcb27936f6bc81df6d8e4c85c to your computer and use it in GitHub Desktop.
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.Collections.Generic; | |
using System.Linq; | |
namespace ConsoleApplication1 | |
{ | |
internal static class Program | |
{ | |
private static void Main() | |
{ | |
string[] expectedColumns = | |
{ | |
"COLUMN1", | |
"COLUMN2", | |
"COLUMN3" | |
}; | |
string[] actualColumns = | |
{ | |
"COLUMN1", | |
"coluMN2", | |
"EXTRA1" | |
}; | |
// here's where your logic starts. | |
Dictionary<string, string> expectedMapping = expectedColumns.ToDictionary(x => x, StringComparer.OrdinalIgnoreCase); | |
foreach (string actualColumn in actualColumns) | |
{ | |
string expectedColumn; | |
if (!expectedMapping.TryGetValue(actualColumn, out expectedColumn)) | |
{ | |
Console.WriteLine($"WARNING: extra unexpected column ({actualColumn} wasn't expected.)"); | |
continue; | |
} | |
// remove it to enable the "missing expected columns" loop | |
expectedMapping.Remove(actualColumn); | |
if (!expectedColumn.Equals(actualColumn, StringComparison.Ordinal)) | |
{ | |
Console.WriteLine($"WARNING: case-insensitive match (expected {expectedColumn}, got {actualColumn})"); | |
} | |
} | |
// TODO: you'd actually have a "column name and importance enum" in this loop. | |
foreach (string missingColumn in expectedMapping.Values) | |
{ | |
Console.WriteLine($"CRITICAL: missing column ({missingColumn} wasn't found)"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment