Partial Types in C#
-
I can't seems to find any good use of partial types. It doesn't work like include file, instead just let you to split a class into different files. If I have code I don't want to see, putting them into a simple region is good enought. Even for designer-generated code, I prefer having them inside one file, since those code are required for the UI class to work. Anyone found any good use of partial types??? (I have a strong feeling that the new 'var' feature in C# 3.0 is kind of 'not of useful' as well.)
-
I can't seems to find any good use of partial types. It doesn't work like include file, instead just let you to split a class into different files. If I have code I don't want to see, putting them into a simple region is good enought. Even for designer-generated code, I prefer having them inside one file, since those code are required for the UI class to work. Anyone found any good use of partial types??? (I have a strong feeling that the new 'var' feature in C# 3.0 is kind of 'not of useful' as well.)
EscapeKey wrote:
Anyone found any good use of partial types???
What they're currently used for, I prefer having the designer code seperate since my dev machines aren't that fast and having the designer code in a seperate file saves the editor loading potentially several thousand lines of code.
As of how to accomplish that have you ever tried Google? Failing that try :badger::badger::badger:.
-
I can't seems to find any good use of partial types. It doesn't work like include file, instead just let you to split a class into different files. If I have code I don't want to see, putting them into a simple region is good enought. Even for designer-generated code, I prefer having them inside one file, since those code are required for the UI class to work. Anyone found any good use of partial types??? (I have a strong feeling that the new 'var' feature in C# 3.0 is kind of 'not of useful' as well.)
I've been using it with generated code. Basically a class has a bunch of generated content in one .cs and the 'custom' code in the other. I'm talking generated oo-relational mapping classes here.
-
I can't seems to find any good use of partial types. It doesn't work like include file, instead just let you to split a class into different files. If I have code I don't want to see, putting them into a simple region is good enought. Even for designer-generated code, I prefer having them inside one file, since those code are required for the UI class to work. Anyone found any good use of partial types??? (I have a strong feeling that the new 'var' feature in C# 3.0 is kind of 'not of useful' as well.)
EscapeKey wrote:
Anyone found any good use of partial types???
Other than splitting up huge source files, which was the one thing I hated about C# coming from a C++ environment, no. But look at how the designer uses partial classes--it separates the code generated stuff from your manual coded stuff, which is pretty slick. Marc
People are just notoriously impossible. --DavidCrow
There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer
People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith -
I can't seems to find any good use of partial types. It doesn't work like include file, instead just let you to split a class into different files. If I have code I don't want to see, putting them into a simple region is good enought. Even for designer-generated code, I prefer having them inside one file, since those code are required for the UI class to work. Anyone found any good use of partial types??? (I have a strong feeling that the new 'var' feature in C# 3.0 is kind of 'not of useful' as well.)
Partial Classes are just a waste of time if not used for generated code! http://alpascual.com/blog/al/archive/2006/07/25/Problems-using-Visual-Studio-2005-auto-generated-DataSets-.aspx[^] Cheers Al
-
Partial Classes are just a waste of time if not used for generated code! http://alpascual.com/blog/al/archive/2006/07/25/Problems-using-Visual-Studio-2005-auto-generated-DataSets-.aspx[^] Cheers Al
Actually they are rather handy if you're using a version tool that doesn't support multiple checkouts and sourcecode merging.
"God doesn't play dice" - Albert Einstein "God not only plays dice, He sometimes throws the dices where they cannot be seen" - Niels Bohr
-
I can't seems to find any good use of partial types. It doesn't work like include file, instead just let you to split a class into different files. If I have code I don't want to see, putting them into a simple region is good enought. Even for designer-generated code, I prefer having them inside one file, since those code are required for the UI class to work. Anyone found any good use of partial types??? (I have a strong feeling that the new 'var' feature in C# 3.0 is kind of 'not of useful' as well.)
I think it's a natural evolution if we come back to look at namespace. VS.NET IDE makes some good use of it by separating designer code. However, the keyword "partial" doesn't seem to be necessary (we define partial namespace without "partial" keyword).
Best, Jun
-
I can't seems to find any good use of partial types. It doesn't work like include file, instead just let you to split a class into different files. If I have code I don't want to see, putting them into a simple region is good enought. Even for designer-generated code, I prefer having them inside one file, since those code are required for the UI class to work. Anyone found any good use of partial types??? (I have a strong feeling that the new 'var' feature in C# 3.0 is kind of 'not of useful' as well.)
They are very useful for Xaml-based development. If you have a.xaml and a.xaml.cs, the class in a.xaml.cs is partially declared, and a.xaml is used to generate a temp cs file which completes the partial definition of the class. See my blog entry : http://blog.voidnish.com/?p=126[^] for more info on this.
Regards, Nish
Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
Currently working on C++/CLI in Action for Manning Publications. Also visit the Ultimate Toolbox blog (New) -
I can't seems to find any good use of partial types. It doesn't work like include file, instead just let you to split a class into different files. If I have code I don't want to see, putting them into a simple region is good enought. Even for designer-generated code, I prefer having them inside one file, since those code are required for the UI class to work. Anyone found any good use of partial types??? (I have a strong feeling that the new 'var' feature in C# 3.0 is kind of 'not of useful' as well.)
I recently had an application with an abstracted database layer that was encapsulated into one class. The partial class concept helped me divide this layer into files, each one of which represented a table or tables. In each of these files I also added the abstract class to be used by the upper layers. This made synchronizing the two very easy and greatly helped working with specific items in isolation of the rest. In another module I separated a settings class into multiple files. The public interface was in one file while the private interfaces, which did all the busy work, were kept in separate files according to what their class of settings were. In both cases, the maintainability of the code was greatly increased. It also simplified the situation of multiple developers working in the same class. As for the "var" feature in 3.0; I prefer explicitly defined objects for clarity, even if it means a little extra typing. However, I can see where this could be useful in some specific circumstances. Unfortunately, I think it will be abused by lazy programmers.
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
I can't seems to find any good use of partial types. It doesn't work like include file, instead just let you to split a class into different files. If I have code I don't want to see, putting them into a simple region is good enought. Even for designer-generated code, I prefer having them inside one file, since those code are required for the UI class to work. Anyone found any good use of partial types??? (I have a strong feeling that the new 'var' feature in C# 3.0 is kind of 'not of useful' as well.)
-
I recently had an application with an abstracted database layer that was encapsulated into one class. The partial class concept helped me divide this layer into files, each one of which represented a table or tables. In each of these files I also added the abstract class to be used by the upper layers. This made synchronizing the two very easy and greatly helped working with specific items in isolation of the rest. In another module I separated a settings class into multiple files. The public interface was in one file while the private interfaces, which did all the busy work, were kept in separate files according to what their class of settings were. In both cases, the maintainability of the code was greatly increased. It also simplified the situation of multiple developers working in the same class. As for the "var" feature in 3.0; I prefer explicitly defined objects for clarity, even if it means a little extra typing. However, I can see where this could be useful in some specific circumstances. Unfortunately, I think it will be abused by lazy programmers.
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
Yes, the potential for abuse is quite something, but I come across legit applications quite often.