[Translation] Visual Basic 2005 Enhancements (Nine) Part Types on Language

xiaoxiao2021-03-06  38

Part of the type allows the same type to be defined in different source files. In one of the files, the type definition that can be performed in a normal manner (the author said "ordinary" means no need to use

Partial keyword, 淌 注):

Public Class TestPartial

'Code……

END CLASS

And in other source files, you have to use

Partial keywords tell the compiler, this code is an extension for the original class definition:

Partial Public Class TestPartial

'Code……

END CLASS

The code generated by the IDE is marked

Partial keyword, and the code filled in with the user is separated. You add a name in the project

TestForm's form to see the generated source file. You might be surprised, because in addition to the empty frame of the form class, it is empty. Where are the code generated by the designer generated in the "Windows Form Automatic Generation" area?

Now, the code generated by the designer is stored in the TestForm.Designer.vb file, you can click on the solution browser toolbar.

Show All Files Press the button to read this file. You should not modify the code in this file (actually you can modify, just don't recommend this,), but if you want to reserve some things when you are still generated again, you can Paste the required code to the Testform.vb file.

The engineering team can use some of the advantages to assign each developer to write a task of a certain class file of the same class. Multi-person development no longer needs to share access to the same source file, because you can now disperse the definition of the same class into multiple source files.

@ 以下 below is the original text for netizens reference @

Partial Types

Partial Types Allow Definition of a Single Type Across Multiple Source Files. The Type Definition Has A Normal Declaration in One File:

Public Class TestPartial

'Implement ...

END CLASS

In Other Source Files, you use the

Partial Keyword To Tell The Compiler That this code is a payion of the original class definition:

Partial Public Class TestPartial

'Implement ...

END CLASS

Code in classes generated by designers in the IDE IS marked with the

Partial Keyword, and is subjected from user code. Add a form named

TestForm to a project and look at the resulting source file. You may be surprised to see that it's empty except for the form's class declaration. Where's all the designer-generated code that used to go inside the Windows Form Designer Generated Code region?

The designer-generated code is now placed in file TestForm.designer.vb, which you can see by clicking theShow All Files button in the Solution Explorer toolbar. You should not change the code in this file, but you can copy and paste what You NEED INTO The Testform.vb File if you want to preserve something when the designer file is later regenerated.

Project teams can take advantage of partial classes by giving each developer a file containing their portion of the class. Multiple developers no longer need to share access to the same source files since you can now separate a class definition into multiple source files.

转载请注明原文地址:https://www.9cbs.com/read-71735.html

New Post(0)