Assemblyinfo. CS file: an attribute file containing the program version, information, and copyright (transfer)

Source: Internet
Author: User

Assemblyinfo. CS file: Property file containing the program version, information, and copyright

First, we will introduce the Assembly attributes in the assemblyinfo. CS file.

Content:

Using system. reflection; using system. runtime. compilerservices;

[Assembly: assemblytitle ("")] [Assembly: assemblydescription ("")] [Assembly: assemblyconfiguration ("")] [Assembly: assemblycompany ("")] [assembly: assemblyproduct ("")] [Assembly: assemblycopyright ("")] [Assembly: assemblytrademark ("")] [Assembly: assemblyculture ("")] [assembly: assemblyversion ("1. 0. * ")] [Assembly: assemblydelaysign (false)] [Assembly: assemblykeyfile (" ")] [Assembly: assemblykeyname (" ")]

Its significance is as follows: 1. [Assembly: assemblytitle ("")]

[Assembly: assemblytitle ("")] in the code ":" The preceding Assembly indicates that this attribute works within the Assembly range. Type name: system. reflection. assemblytitleattribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblytitleattribute: attribute function: This attribute describes the Assembly name, such as the module of a project in a certain company. This name can be a legal string, there can be spaces.

2. [Assembly: assemblydescription ("")] type name: system. reflection. assemblydescriptionattribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblydescriptionattribute: attribute function: a simple description of an Assembly, such as a function or language.

3. [Assembly: assemblydescription ("")] type name: system. reflection. assemblydescriptionattribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblydescriptionattribute: attribute function: a simple description of an assembly, which describes the functions, features, and constraints of the Assembly.

4. [Assembly: assemblyconfiguration ("")] type name: system. reflection. assemblyconfigurationattribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblyconfigurationattribute: attribute function: assembly configuration information, such as retail, release, debugging, etc ,. net runtime does not use this attribute

5. [Assembly: assemblycompany ("")] type name: system. reflection. assemblycompanyattribute attribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblycompanyattribute: attribute function: name of the company to which the Assembly belongs

6. [Assembly: assemblyproduct ("")] type name: system. reflection. assemblyproductattribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblyproductattribute: attribute function: the product name described in the Assembly

7. [Assembly: assemblycopyright ("")] type name: system. reflection. assemblycopyrightattribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblycopyrightattribute: attribute function: copyright information of the Assembly

8. [Assembly: assemblytrademark ("")] type name: system. reflection. assemblytrademarkattribute attribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblytrademarkattribute: attribute function: Trademark Information of an assembly

9. [Assembly: assemblyculture ("")] type name: system. reflection. assemblycultureattribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblycultureattribute: attribute function: enumerated fields indicate the regions supported by the Assembly. An assembly can also specify regional independence, indicating that it contains resources for the default culture. The runtime processes the assemblies that are not set to NULL for any regional properties by the affiliated assemblies. This type of assembly is subject to the binding rules of the affiliated Assembly. For more information, see how the runtime locates the assembly.

10. [Assembly: assemblyversion ("")] type name: system. reflection. assemblyversionattribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblyversionattribute: attribute function: the Assembly version information. The version information is saved in four stages, namely, the master. secondary. internal version. modify the version. This value is used by the CLR in the strong-name assembly for binding operations. You can use the wildcard * to replace the internal version and modify the version. Vs will automatically generate the version number for it. For example, if it is defined as "1. 0. *", Vs will automatically generate the following part. If it is set to *, the version number is automatically changed after each program modification.

11. [Assembly: assemblydelaysign (false)] type name: system. reflection. assemblydelaysignattribute attribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblydelaysignattribute: attribute function: whether to use delayed Signature

12. [Assembly: assemblykeyfile ("")] type name: system. reflection. assemblykeyfileattribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblykeyfileattribute: attribute function: contains the Public Key (if delayed signature is used) or the file name that contains both the public key and the private key. This public key and private key are passed as parameters to the constructor of this attribute. The file name is related to the output file (.exe or. dll) and has nothing to do with the source file path.

13. [Assembly: assemblykeyname ("")] type name: system. reflection. assemblykeynameattribute Declaration: [attributeusage (attributetargets. assembly)] public sealed class assemblykeynameattribute: attribute function: indicates the key container that contains the key pair (the constructor passed as the parameter to this attribute.

So how to read the file information? You can use the following methods:

Object [] ATT = assembly. getcustomattributes (typeof (assemblydescriptionattribute), false); String title = (assemblydescriptionattribute) ATT [0]). description; system. windows. forms. messageBox. show (title. tostring ());

You can access different attributes by changing the parameters in typeof. Note that you must convert the type of ATT.

The other two files in the properties folder, resources. resx and settings. settings, are managed by resources and configurations. (See, how important it is to learn a foreign language !)

 

Speaking of these two files, We have to first talk about the app. config file under the project root directory:

It is a standard XML file, settings. all properties set by settings are in the app. config indicates that you can configure it to the app. write the desired parameters in the config file. Of course, this method is not only used to write the app. config file. For example, if you want to write the database connection information to app. config and call it easily when you connect to the database, you can do this:

1. Add the following code to the app. config file:

<Deleetask>

<Add key = "connstr" value = "Data Source = data source address; user = *****; Password = ******"/>

</Appsettings>

2. Call the following statement in the program to extract the database connection information:

String connstr;

Connstr = system. configuration. configurationmanager. receivettings ["connstr"]. tostring ();

In this case, the value of connstr is "Data Source = data source address; user = *****; Password = *****". We can use this database connection information to connect to the database.

The advantage of this is that our program can easily connect to multiple different databases. We can put the information of different databases into the app. config file at the same time and call it as needed.

 

In contrast, the above method is more earthy. It can only store string-type parameters, while settings. the settings file is a page provided by Microsoft for users to set configuration information. It is more powerful and has a wider application scope. It not only saves strings, but also stores object information such as date and time.

For example, I added two user-level configuration information, one of which is string type and the other is Date and Time type. After saving, the following code appears in the app. config file:

<Usersettings>

<Test. properties. Settings>

<Setting name = "setting2" serializeas = "string">

<Value> Data Source = *** _ #####; [email protected]; Password = % </value>

</Setting>

<Setting name = "setting3" serializeas = "string">

<Value> 2009-03-16 </value>

</Setting>

</Test. properties. Settings>

</Usersettings>

It is easy to set up and can be done with a few clicks.

Take the database connection string as an example. The read method is as follows:

Connstr = test. properties. settings. Default. setting2.tostring ();

We can see that the information has been encapsulated into different objects for reading.

 

Let's talk about resources. resx.

Resources. resx manages non-source code files in the program, including images, audios, strings, icons, and other files. We can find "add and edit resources" on msdn to read how to use it, there is a detailed process for accessing and adding resources, which will not be repeated here.

 

Program. CS file:

The application. Run (New Main. Main (); statement marks your startup window. You can change the parameters to set your inspiration interface.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/zclzzz/archive/2010/10/08/5927081.aspx

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.