Editorials

Partial Classes

SSWUGtv
With Stephen Wynkoop
The end of the year is coming soon. One of the many things that happens at the end of the year is a review of your peformance this past year. Many companies have their employees set goals for personal development. Acheiving these goals may have impact on promotions, salary, project assignments, etc. Watch the show today as Laura Rose shares ideas how to design an above-average performance review goal?
Watch the Show

Partial Classes
Partial Classes have been supported in Dot Net for a number of releases. I’ve used them extensively, seen them demonstrated from time to time, and seen them misused a number of times. When used correctly, they grant a great deal of flexibility for the programmer.

When you create a partial class you state the case in the class definition. The class is then defined in two or more separate files. Typically, it is defined in two files.

Most often, this is used in those environments where you have auto-generated code against which you wish to add your own customizations. If you added your customizations to the generated code, then the code can not be generated a second time without overwriting and losing all your customizations.

Using partial classes allows you to place your code in a separate file that completes the partial class definition. Then when you re-generate code from a tool such as Entity framework, your extensions, being in a completely separate file not managed by the generator, remain intact. You may have to make some modifications to your custom code, but what you have written is not lost during the generation process.

Partial classes are handled by the compiler. When the compiler sees a class defined as partial class, it looks through all remaining project source code code for any other files with that same partial class designation. The different code files are appended and then the class is fully generated. This allows you to have a class identified as being a partial class without actually having a second file extending the class. There is no required linkage between the two code files other than the class designation and namespace.

Share your tips for software automation by writing to btaylor@sswug.org.

Cheers,

Ben

$$SWYNK$$

Featured Article(s)
Trends in Database Technology
This article discusses about the recent trends in database management generally. The topic related to the modifications in current database system according to the volume of the business.

Featured White Paper(s)
Encryption & Key Management for Microsoft SQL Server 2008/2012
Simplify encryption and key management on your SQL Server. Data thieves are targeting SMB companies because of their inadequa… (read more)