Make GetValueByColumnName a generic extension method
Refactored GetValueByColumnName to use a generic type parameter constrained to class types. This enhances type safety and enables better type inference and static analysis when accessing property values by column name.
This commit is contained in:
@@ -9,7 +9,7 @@ public static class ReflectionExtensions
|
||||
/// Gets the value of a property by its column name defined in <see cref="ColumnAttribute"/>.
|
||||
/// Returns <c>null</c> if no property with the given column name exists.
|
||||
/// </summary>
|
||||
public static object? GetValueByColumnName(this object obj, string columnName)
|
||||
public static object? GetValueByColumnName<T>(this T obj, string columnName) where T : class
|
||||
{
|
||||
var property = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||
.FirstOrDefault(p => p.GetCustomAttribute<ColumnAttribute>()?.Name == columnName);
|
||||
|
||||
Reference in New Issue
Block a user