How to reference Assembly attributes

  • Thread starter Thread starter AlexB
  • Start date Start date
A

AlexB

A windows forms .NET application has various built in
attributes like:

<Assembly: AssemblyTitle("MyAssembly")>
<Assembly: AssemblyDescription("Blahblah")>
<Assembly: AssemblyCompany("XYZ")>

But how can I reference these from within my windows forms
application???
 
Hi,

Thanks for your post.

1. We can call the method GetCustomAttributes() under
System.Reflection.Assembly to get the custom attributes for the assembly.
System.Reflection namespace contains a list of assembly attribute classes
that you are interested say, AssemblyTitleAttribute,
AssemblyDescriptionAttribute, AssemblyCompanyAttribute, etc. Please refer
to the following MSDN documentation:

Assembly.GetCustomAttributes
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemreflectionassemblyclassgetcustomattributestopic.asp?frame=true

System.Reflection Namespace
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemreflection.asp?frame=true

2. Calling GetCustomAttributes(true) will return an object array of all the
attributes. We are able to loop through the array to get each attribute.
The following code snippet call GetCustomAttributes(type, true) which
returns AssemblyTitleAttribute specifically.

//--------------code snippet-------------------
using System.Reflection;
...
AssemblyTitleAttribute assemlyTitle;// = new AssemblyTitleAttribute("");
object [] objAttributes =
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttr
ibute),true);
assemlyTitle = (AssemblyTitleAttribute)objAttributes[0];
MessageBox.Show (assemlyTitle.Title);
//-------------------end of-----------------------

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top