Rename class and update namespace for placeholder logic
Renamed the ReflectionExtensions class to PlaceholderExtensions and moved it from the ReC.Domain.Extensions namespace to ReC.Application.Common.Behaviors.InvokeAction to better reflect its purpose and location within the project structure.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ReC.Application.Common.Behaviors.InvokeAction;
|
||||
|
||||
public static class PlaceholderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 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<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);
|
||||
|
||||
return property?.GetValue(obj);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user