From 742b7e99aa3f65f360234de367b80207986988fa Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 8 Nov 2018 13:03:23 -0500 Subject: [PATCH] feat: Adding method for getting properties with a given attribute type --- ICD.Common.Utils/AttributeUtils.cs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ICD.Common.Utils/AttributeUtils.cs b/ICD.Common.Utils/AttributeUtils.cs index beda60c..74dc221 100644 --- a/ICD.Common.Utils/AttributeUtils.cs +++ b/ICD.Common.Utils/AttributeUtils.cs @@ -119,7 +119,7 @@ namespace ICD.Common.Utils if (s_CachedTypes.Contains(type)) return; - + s_CachedTypes.Add(type); try @@ -214,6 +214,28 @@ namespace ICD.Common.Utils return s_AttributeToTypeCache[attribute]; } + /// + /// Returns the properties on the given instance with property attributes of the given type. + /// + /// + /// + /// + /// + public static IEnumerable GetProperties(object instance, bool inherit) + { + if (instance == null) + throw new ArgumentNullException("instance"); + + return instance.GetType() +#if SIMPLSHARP + .GetCType() +#else + .GetTypeInfo() +#endif + .GetProperties() + .Where(p => ReflectionExtensions.GetCustomAttributes(p, inherit).Any()); + } + #endregion } }