Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to override default field comparer used in DapperTable (EX: e… #716

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Dapper/SqlMapper.DapperTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ namespace Dapper
{
partial class SqlMapper
{
private static IEqualityComparer<string> DefaultFieldNameComparer = StringComparer.Ordinal;

/// <summary>
/// Ability to override default field comparer (EX: enable case insensitive comparison)
/// </summary>
/// <param name="comparer"></param>
public static void SetFieldNameComparer(IEqualityComparer<string> comparer)
{
DefaultFieldNameComparer = comparer;
}

private sealed class DapperTable
{
string[] fieldNames;
Expand All @@ -17,7 +28,7 @@ public DapperTable(string[] fieldNames)
if (fieldNames == null) throw new ArgumentNullException(nameof(fieldNames));
this.fieldNames = fieldNames;

fieldNameLookup = new Dictionary<string, int>(fieldNames.Length, StringComparer.Ordinal);
fieldNameLookup = new Dictionary<string, int>(fieldNames.Length, DefaultFieldNameComparer);
// if there are dups, we want the **first** key to be the "winner" - so iterate backwards
for (int i = fieldNames.Length - 1; i >= 0; i--)
{
Expand Down