A division class or structure can contain a division method. A part of the class contains the signature of the method. You can define optional implementations in the same or another part. If this implementation is not provided, the method will be removed during compilation and all calls to the method. The division method enables the implementers of a certain part of the class to define methods (similar to events ). The implementers of another part of the class can decide whether to implement this method. If this method is not implemented, the compiler will remove the method signature and all calls to this method. This method is called, including any calculation results in the call, without any impact at runtime. Therefore, anyCodeYou can use the division method at will, even if no implementation is provided. If an unimplemented method is called, it will not cause compilation errors or runtime errors. The division method is particularly useful when you customize the generated code. These methods allow you to retain the method name and signature, so the generated code can call the method, and the developer can decide whether to implement the method. Similar to the Division class, the division method enables the Code created by the Code Generator to work together with the Code created by the developer without running overhead. The division method declaration consists of two parts: definition and implementation. They can be located in different parts of the segmentation class, or in the same part. If there is no implementation declaration, the compiler will optimize the definition Declaration and all calls to the method.
- Restrictions
-
- The partial method declaration must begin with the following keyword partial, and the method must return void.
- The division method can have the ref parameter, but not the out parameter.
- The partial method is an implicit private method, so it cannot be a virtual method.
- The division method cannot be the extern method, because the existence of the subject determines whether the method is defined or implemented.
- The division method can have static and unsafe modifiers.
- The division method can be generic. The constraint will be placed on the definition of the division method declaration, but you can also choose to repeat it on the Implementation declaration. The parameter and type parameter names do not need to be the same in the implementation declaration and definition declaration.
- You can generate a delegate for a defined and implemented branch method, but not for a defined but not implemented branch method.
partial void onnamechanged (); partial void onnamechanged () {} |