. Net reads the AssemblyInfo. cs attribute value of the project.

Source: Internet
Author: User

We write all those code repetitively for dynamic assembly loading and checking to verify few properties on assemblies. it wocould be a great stop to write all such things in the assemblyinfo. cs (because it needs to completely describe the assembly that it is intended to serve) You can define your About form of the application entirely using the AssemblyInfo. cs
How to use the following info:
AssemblyInfo ainfo = new AssemblyInfo ();
FrmAbout. Text = ainfo. Title;
FrmAbout. menuAbt. Text = string. Format ("& About {0} ..", ainfo. Title );
FrmAbout. Text = "About" + this. Owner. Text;
FrmAbout. Icon = this. Owner. Icon;
// You can set the icon like this on the abt form.
FrmAbout. pictureBox1.Image = this. Owner. Icon. ToBitmap ();
FrmAbout. lblTitle. Text = ainfo. Title;
FrmAbout. lblVersion. Text = ainfo. Version;
FrmAbout. lblCopyright. Text = ainfo. Copyright;
FrmAbout. lblDescription. Text = ainfo. Description;
FrmAbout. lblCodebase. Text = ainfo. CodeBase;
The following is the specific implementation code.
Using System;
Using System. Reflection;
Using System. Runtime. CompilerServices;
[Assembly: AssemblyTitle ("Demo Title")]
[Assembly: AssemblyDescription ("Demo app that reads from the Assembly Info file description")]
[Assembly: AssemblyConfiguration ("")]
[Assembly: AssemblyCompany ("World Company")]
[Assembly: AssemblyProduct ("Not for your cial use.")]
[Assembly: AssemblyCopyright ("open source (US)")]
[Assembly: AssemblyTrademark ("")]
[Assembly: AssemblyCulture ("")]
[Assembly: CLSCompliant (true)]
[Assembly: AssemblyDelaySign (false)]
[Assembly: AssemblyKeyFile ("")]
[Assembly: AssemblyKeyName ("")]
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// By using the '*' as shown below:
[Assembly: AssemblyVersion ("1.0.1.1")]
# Region "Class to get the information for AboutForm"
/* This class uses the System. Reflection. Assembly class to access assembly meta-data.
* This class is not a normal feature of AssmblyInfo. cs */
/// <Summary>
/// AssemblyInfo class.
/// </Summary>
Public class AssemblyInfo
{
// Used by functions to access information from Assembly Attributes
/// <Summary>
/// MyType.
/// </Summary>
Private Type myType;
/// <Summary>
/// Initializes a new instance of the <see cref = "AssemblyInfo"/> class.
/// </Summary>
Public AssemblyInfo ()
{
// Shellform here denotes the actual form.
MyType = typeof (ShellForm );
}
/// <Summary>
/// Gets the name of the assembly.
/// </Summary>
/// <Value> The name of the assembly. </value>
Public String AssemblyName
{
Get
{
Return myType. Assembly. GetName (). Name. ToString ();
}
}
/// <Summary>
/// Gets the full name of the assembly.
/// </Summary>
/// <Value> The full name of the assembly. </value>
Public String AssemblyFullName
{
Get
{
Return myType. Assembly. GetName (). FullName. ToString ();
}
}
/// <Summary>
/// Gets the code base.
/// </Summary>
/// <Value> The code base. </value>
Public String CodeBase
{
Get
{
Return myType. Assembly. CodeBase;
}
}
/// <Summary>
/// Gets the copyright.
/// </Summary>
/// <Value> The copyright. </value>
Public String Copyright
{
Get
{
Type att = typeof (AssemblyCopyrightAttribute );
Object [] r = myType. Assembly. GetCustomAttributes (att, false );
AssemblyCopyrightAttribute copyattr = (AssemblyCopyrightAttribute) r [0];
Return copyattr. Copyright;
}
}
/// <Summary>
/// Gets the company.
/// </Summary>
/// <Value> The company. </value>
Public String Company
{
Get
{
Type att = typeof (AssemblyCompanyAttribute );
Object [] r = myType. Assembly. GetCustomAttributes (att, false );
AssemblyCompanyAttribute compattr = (AssemblyCompanyAttribute) r [0];
Return compattr. Company;
}
}
/// <Summary>
/// Gets the description.
/// </Summary>
/// <Value> The description. </value>
Public String Description
{
Get
{
Type att = typeof (AssemblyDescriptionAttribute );
Object [] r = myType. Assembly. GetCustomAttributes (att, false );
AssemblyDescriptionAttribute descattr = (AssemblyDescriptionAttribute) r [0];
Return descattr. Description;
}
}
/// <Summary>
/// Gets the product.
/// </Summary>
/// <Value> The product. </value>
Public String Product
{
Get
{
Type att = typeof (AssemblyProductAttribute );
Object [] r = myType. Assembly. GetCustomAttributes (att, false );
AssemblyProductAttribute prodattr = (AssemblyProductAttribute) r [0];
Return prodattr. Product;
}
}
/// <Summary>
/// Gets the title.
/// </Summary>
/// <Value> The title. </value>
Public String Title
{
Get
{
Type att = typeof (AssemblyTitleAttribute );
Object [] r = myType. Assembly. GetCustomAttributes (att, false );
AssemblyTitleAttribute titleattr = (AssemblyTitleAttribute) r [0];
Return titleattr. Title;
}
}
/// <Summary>
/// Gets the version.
/// </Summary>
/// <Value> The version. </value>
Public String Version
{
Get
{
Return myType. Assembly. GetName (). Version. ToString ();
}
}
}
# Endregion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.