Skip to content

Instantly share code, notes, and snippets.

@jpdillingham
Created December 30, 2016 03:50
Show Gist options
  • Save jpdillingham/32fb0a43b8f53a6973ae4a5f07d4e5fa to your computer and use it in GitHub Desktop.
Save jpdillingham/32fb0a43b8f53a6973ae4a5f07d4e5fa to your computer and use it in GitHub Desktop.
/// <summary>
/// Returns a value indicating whether <see cref="Type"/> of the specified object instance contains the specified <see cref="Attribute"/>.
/// </summary>
/// <typeparam name="T">The <see cref="Attribute"/> for which to check.</typeparam>
/// <param name="instance">The object instance to check.</param>
/// <returns>A value indicating whether the specified Type contains the specified Attribute.</returns>
public static bool HasCustomAttribute<T>(this object instance) where T : Attribute
{
return Attribute.GetCustomAttribute(instance.GetType(), typeof(T)) != default(Attribute);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment