mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-17 05:35:07 +00:00
feat: Adding method for getting properties with a given attribute type
This commit is contained in:
@@ -214,6 +214,28 @@ namespace ICD.Common.Utils
|
|||||||
return s_AttributeToTypeCache[attribute];
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user