Skip to content

Instantly share code, notes, and snippets.

@jpdillingham
Created December 26, 2016 23:49
Show Gist options
  • Save jpdillingham/14a28c27fdacd6cffdc8255e90260379 to your computer and use it in GitHub Desktop.
Save jpdillingham/14a28c27fdacd6cffdc8255e90260379 to your computer and use it in GitHub Desktop.
/// <summary>
/// Returns the specified assembly attribute of the specified assembly.
/// </summary>
/// <typeparam name="T">The assembly attribute to return.</typeparam>
/// <param name="assembly">The assembly from which to retrieve the attribute.</param>
/// <returns>The retrieved attribute.</returns>
public static T GetAssemblyAttribute<T>(this System.Reflection.Assembly assembly) where T : Attribute
{
object[] attributes = assembly.GetCustomAttributes(typeof(T), false);
if (attributes == null || attributes.Length == 0)
{
return null;
}
return attributes.OfType<T>().SingleOrDefault();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment