How to reference Assembly attributes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AlexB

    How to reference Assembly attributes

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

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

    But how can I reference these from within my windows forms
    application???
  • Tian Min Huang

    #2
    RE: How to reference Assembly attributes

    Hi,

    Thanks for your post.

    1. We can call the method GetCustomAttrib utes() under
    System.Reflecti on.Assembly to get the custom attributes for the assembly.
    System.Reflecti on namespace contains a list of assembly attribute classes
    that you are interested say, AssemblyTitleAt tribute,
    AssemblyDescrip tionAttribute, AssemblyCompany Attribute, etc. Please refer
    to the following MSDN documentation:

    Assembly.GetCus tomAttributes

    frlrfsystemrefl ectionassemblyc lassgetcustomat tributestopic.a sp?frame=true

    System.Reflecti on Namespace

    frlrfsystemrefl ection.asp?fram e=true

    2. Calling GetCustomAttrib utes(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 GetCustomAttrib utes(type, true) which
    returns AssemblyTitleAt tribute specifically.

    //--------------code snippet-------------------
    using System.Reflecti on;
    ...
    AssemblyTitleAt tribute assemlyTitle;// = new AssemblyTitleAt tribute("");
    object [] objAttributes =
    Assembly.GetExe cutingAssembly( ).GetCustomAttr ibutes(typeof(A ssemblyTitleAtt r
    ibute),true);
    assemlyTitle = (AssemblyTitleA ttribute)objAtt ributes[0];
    MessageBox.Show (assemlyTitle.T itle);
    //-------------------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.

    Comment

    Working...