Application characteristics of local types: the attributes on the local type have an "additive" effect.[Attribute1, Attribute2 ("Hello")]
Partial class class1{}
[Attribute3, Attribute2 ("Exit")]
Partial class class1{}
Equivalent
[Attribute1, Attribute2 ("Hello"), Attribute3, Attribute2 ("Exit")]
Class Class1 {}
Note: The Attribute2 property allows multiple use on a class.
It is a good programming habit to keep all the source code as a type in a separate file, but sometimes a type becomes too large to be an unrealistic constraint. In addition, programmers often use source code generators to produce an initial structure of an application, and then modify the resulting code. Unfortunately, when the source code is released again sometime in the future, the existing changes will be overwritten. The Partial types allows classes, structs, and interfaces to be broken into different source code files for multiple fragment fragments in order to simplify development and maintenance. Plus the partial types allows machine-generated and user-written parts to be separated, which makes it easy to add code generated by the tool.
Partial, is a new type modifier that is used when a type is defined in multiple parts. The following is an example of a partial class, implemented in two parts. These two parts may be in two different source code files, for example the first part is generated by a database mapping tool, and the second part is hand-written.
public partial class Customer
{
private int id;
private string name;
private string address;
Private list<order> orders;
Public Customer () {
}
}
public partial class Customer
{
public void SubmitOrder (order order) {
Orders. ADD (order);
}
public bool Hasoutstandingorders () {
return orders. Count > 0;
}
}
When the above two sections are compiled together, the resulting code is as if the class were written in a single unit.
public class Customer
{
private int id;
private string name;
private string address;
Private list<order> orders;
Public Customer () {
}
public void SubmitOrder (order order) {
Orders. ADD (order);
}
public bool Hasoutstandingorders () {
return orders. Count > 0;
}
}
All parts of a partial type must be compiled together so that all the parts can be combined at compile time. In particular, the partial types is not allowed to join a compiled type