Prüft ob ein Property mit dem angegebenen Attribut markiert ist.
/// Determines whether the specified property has given attribute.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="property">The property.</param>
/// <param name="inherit">if set to <c>true</c> baseclasses will be also scanned.</param>
/// <returns>
/// <c>true</c> if the specified property has the attribute; otherwise, <c>false</c>.
/// </returns>
public static bool HasAttribute<T>(this PropertyInfo property, bool inherit) where T : System.Attribute
{
Contract.Requires<ArgumentException>(property != null);
bool exists = false;
object[] list = property.GetCustomAttributes(typeof(T), inherit);
exists = list != null && list.Length > 0;
return exists;
}
Kommentare zum Snippet