GetAttribute

    /// <summary>
    /// Extension methods for dealing with an assembly
    /// </summary>
    public static class AssemblyExtensions
    {
        /// <summary>
        /// Loads the configuration from assembly attributes
        /// </summary>
        /// <typeparam name="T">The type of the custom attribute to find.</typeparam>
        /// <param name="callingAssembly">The calling assembly to search.</param>
        /// <returns>The custom attribute of type T, if found.</returns>
        public static T GetAttribute<T>(this Assembly callingAssembly) 
			where T : Attribute
        {
            T result = null;

            // Try to find the configuration attribute for the default logger if it exists
            object[] configAttributes = Attribute.GetCustomAttributes(callingAssembly,
				typeof(T), false);

            // get just the first one
            if (!configAttributes.IsNullOrEmpty())
            {
                result = (T)configAttributes[0];
            }

            return result;
        }
    }
Example:
var attribute = Assembly.GetExecutingAssembly().GetAttribute<InstallPerformanceCounterAttribute>();

Description

Gets the first assembly attribute of the specified type from the assembly it is called from.

Details

Double click on the code to select all.

 

;