From 4b44358af669a84790f55675a36665cb211baefb Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 16:56:35 +0100 Subject: [PATCH] - add method to get inherited attributes for properties --- GBase/Helpers/Attributes.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 GBase/Helpers/Attributes.cs diff --git a/GBase/Helpers/Attributes.cs b/GBase/Helpers/Attributes.cs new file mode 100644 index 0000000..1b4e3a0 --- /dev/null +++ b/GBase/Helpers/Attributes.cs @@ -0,0 +1,19 @@ +// Author: Gockner, Simon +// Created: 2020-11-13 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +using System; +using System.Linq; +using System.Reflection; + +namespace GBase.Helpers +{ + internal static class Attributes + { + public static T GetAttributeFromInheritedInterfaces(this PropertyInfo propertyInfo) where T : Attribute => + propertyInfo.DeclaringType?.GetInterfaces() + .SelectMany(i => i.GetProperties().Where(p => p.Name.Equals(propertyInfo.Name))) + .Select(p => p.GetCustomAttribute()) + .FirstOrDefault(); + } +} \ No newline at end of file