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); + } +}