reading attributes in AssemblyInfo.cs
-
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(); }
-
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(); }