From d8aa032a57cba211cf8e5669988b5ff515ad93f0 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 26 Mar 2026 13:16:04 +0100 Subject: [PATCH] Add ReflectionExtensions for property lookup by column name Introduced a static ReflectionExtensions class with a GetValueByColumnName extension method to retrieve property values by their [Column] attribute name. Also removed an unused folder reference from the project file. --- src/ReC.Application/ReC.Application.csproj | 1 - .../Extensions/ReflectionExtensions.cs | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/ReC.Domain/Extensions/ReflectionExtensions.cs diff --git a/src/ReC.Application/ReC.Application.csproj b/src/ReC.Application/ReC.Application.csproj index 236efdc..fe5448d 100644 --- a/src/ReC.Application/ReC.Application.csproj +++ b/src/ReC.Application/ReC.Application.csproj @@ -25,7 +25,6 @@ - diff --git a/src/ReC.Domain/Extensions/ReflectionExtensions.cs b/src/ReC.Domain/Extensions/ReflectionExtensions.cs new file mode 100644 index 0000000..1eeb191 --- /dev/null +++ b/src/ReC.Domain/Extensions/ReflectionExtensions.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations.Schema; +using System.Reflection; + +namespace ReC.Domain.Extensions; + +public static class ReflectionExtensions +{ + /// + /// Gets the value of a property by its column name defined in . + /// Returns null if no property with the given column name exists. + /// + public static object? GetValueByColumnName(this object obj, string columnName) + { + var property = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance) + .FirstOrDefault(p => p.GetCustomAttribute()?.Name == columnName); + + return property?.GetValue(obj); + } +}