Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. reading attributes in AssemblyInfo.cs

reading attributes in AssemblyInfo.cs

Scheduled Pinned Locked Moved C#
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zuhx
    wrote on last edited by
    #1

    How can I read the pre-existing attributes that are found in the AssemblyInfo.cs file?

    F 1 Reply Last reply
    0
    • Z zuhx

      How can I read the pre-existing attributes that are found in the AssemblyInfo.cs file?

      F Offline
      F Offline
      flipdoubt
      wrote on last edited by
      #2

      I use the following methods to fill the About Box. There may be better ways to do it, as this was some of the first .NET code I wrote, but it works. public string GetCopyright( Assembly a ) { Type tCopyRight = Type.GetType( "System.Reflection.AssemblyCopyrightAttribute" ); Object[] ao = a.GetCustomAttributes( tCopyRight, false ); if( ao != null && ao.Length == 1 ) { AssemblyCopyrightAttribute attribute = ao[0] as AssemblyCopyrightAttribute; if( attribute != null ) return attribute.Copyright; } } public string GetProduct( Assembly a ) { Type tProduct = Type.GetType( "System.Reflection.AssemblyProductAttribute" ); Object[] ao = a.GetCustomAttributes( tProduct, false ); if( ao != null && ao.Length == 1 ) { AssemblyProductAttribute attribute = ao[0] as AssemblyProductAttribute; if( attribute != null ) return attribute.Product; } } public string GetTitle( Assembly a ) { Type tTitle = Type.GetType( "System.Reflection.AssemblyTitleAttribute" ); Object[] ao = a.GetCustomAttributes( tTitle, false ); if( ao != null && ao.Length == 1 ) { AssemblyTitleAttribute attribute = ao[0] as AssemblyTitleAttribute; if( attribute != null ) return attribute.Title; } } public string GetVersion( Assembly a ) { return a.GetName().Version.ToString(); }

      Z 1 Reply Last reply
      0
      • F flipdoubt

        I use the following methods to fill the About Box. There may be better ways to do it, as this was some of the first .NET code I wrote, but it works. public string GetCopyright( Assembly a ) { Type tCopyRight = Type.GetType( "System.Reflection.AssemblyCopyrightAttribute" ); Object[] ao = a.GetCustomAttributes( tCopyRight, false ); if( ao != null && ao.Length == 1 ) { AssemblyCopyrightAttribute attribute = ao[0] as AssemblyCopyrightAttribute; if( attribute != null ) return attribute.Copyright; } } public string GetProduct( Assembly a ) { Type tProduct = Type.GetType( "System.Reflection.AssemblyProductAttribute" ); Object[] ao = a.GetCustomAttributes( tProduct, false ); if( ao != null && ao.Length == 1 ) { AssemblyProductAttribute attribute = ao[0] as AssemblyProductAttribute; if( attribute != null ) return attribute.Product; } } public string GetTitle( Assembly a ) { Type tTitle = Type.GetType( "System.Reflection.AssemblyTitleAttribute" ); Object[] ao = a.GetCustomAttributes( tTitle, false ); if( ao != null && ao.Length == 1 ) { AssemblyTitleAttribute attribute = ao[0] as AssemblyTitleAttribute; if( attribute != null ) return attribute.Title; } } public string GetVersion( Assembly a ) { return a.GetName().Version.ToString(); }

        Z Offline
        Z Offline
        zuhx
        wrote on last edited by
        #3

        Thanks for the reply. I tried something similiar to what you have posted, but nothing is returned for the title. Even thought I have an entry in the Assembly title attribute AssemblyInfo.cs file. Any idea why this might happen ?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups