Path: redb-route/redb.Route.Sql/Mapping/ColumnNameMatcher.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Sql/Mapping/ColumnNameMatcher.cs
----
using System.ComponentModel.DataAnnotations.Schema;
using System.Reflection;
namespace redb.Route.Sql.Mapping;
///
/// Which property a column or parameter name refers to: a property of that name ignoring case, then a property whose
/// carries the name, then the snake_case name read as PascalCase (user_name →
/// UserName). Result rows are mapped to objects and batch items to parameters by this one rule.
///
internal static class ColumnNameMatcher
{
/// The property among that refers to, or null.
internal static PropertyInfo? Find(PropertyInfo[] properties, string name)
{
// Direct case-insensitive match
var property = Array.Find(properties, p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
if (property != null) return property;
// [Column] attribute match
property = Array.Find(properties, p =>
p.GetCustomAttribute()?.Name?.Equals(name, StringComparison.OrdinalIgnoreCase) == true);
if (property != null) return property;
// snake_case → PascalCase: user_name → UserName
var pascal = SnakeToPascal(name);
return Array.Find(properties, p => p.Name.Equals(pascal, StringComparison.OrdinalIgnoreCase));
}
private static string SnakeToPascal(string snake)
{
var parts = snake.Split('_', StringSplitOptions.RemoveEmptyEntries);
return string.Concat(parts.Select(p =>
string.Concat(char.ToUpperInvariant(p[0]).ToString(), p.AsSpan(1))));
}
}