Definition
Partial class is just a way to separate two parts of the code of a class into separate files. It has no secret or special semantics. It is essentially a way to facilitate code organization and indicate to the compiler that the two codes available in the two files with a class of the same name is not a duplication error but one code is complementary to the other and should be compiled as if it were one thing only.
Use
In general this type of artifice should only be used by code generators, so a part is generated in a file and no one should touch this file. In another file have the parts of class code that the programmer can mess with without causing problems.
Of course nothing prevents the programmer from touching the generated part, but it shouldn’t. It is an organizational protection only to make clear which parts can move and which parts can not, but does not protect in fact.
If you are going to create a class that needs to be partial, just use the modifier partial
before class
To indicate that there will be another part, do this in the two files that have the two parts, you need nothing else. But remember that you should only use this if you create a generator and want a part not to be modified.
Partial Method
The above documentation refers to partial method which is a method that only has the declaration without a body. In this case the body will be in the other file. It is a way to ensure that the method signature is not changed in the other file. If it is changed, the compiler will indicate problems.
Do not mess with generated code
So the file you want to move shouldn’t be moved.
Where to find the files
The files usually get together in the project, if not in the same folder, in some other related. Try to check through Windows Explorer all the files available in the project. The file name will probably make some mention of partial or designer or at least have a name similar to the file you want to move and can’t find. If you find it in Windows Explorer, it can be easier to locate it in VS.
See in VS if the files are not grouped in the project. Click on the plus sign [+]
to open the related files. Depending on the summer it may be a triangle or other symbol, but it is the one that opens the file tree.
But I will stress, do not edit this part unless you know a lot what you are doing and know all the implications, which should not be the case.
You want to know the concept of
partial class
or wondering if you can edit the file?– Leonel Sanches da Silva
would like to edit as I am not finding the file, what would be that auto generated.
– henriquedpereira