mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-12 03:05:06 +00:00
feat: Adding method for getting properties with a given attribute type
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the properties on the given instance with property attributes of the given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="instance"></param>
|
||||
/// <param name="inherit"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<PropertyInfo> GetProperties<T>(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<T>(p, inherit).Any());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user