Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Partial Types in C#

Partial Types in C#

Scheduled Pinned Locked Moved The Lounge
csharpdesignquestion
11 Posts 11 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jpg 0
    wrote on last edited by
    #1

    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.)

    E T M A J 8 Replies Last reply
    0
    • J jpg 0

      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.)

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      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:.

      1 Reply Last reply
      0
      • J jpg 0

        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.)

        T Offline
        T Offline
        Tim Kohler
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • J jpg 0

          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.)

          M Offline
          M Offline
          Marc Clifton
          wrote on last edited by
          #4

          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

          Thyme In The Country

          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

          1 Reply Last reply
          0
          • J jpg 0

            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.)

            A Offline
            A Offline
            Albert Pascual
            wrote on last edited by
            #5

            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

            My eMail control My Blog

            J 1 Reply Last reply
            0
            • A Albert Pascual

              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

              My eMail control My Blog

              J Offline
              J Offline
              jan larsen
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • J jpg 0

                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.)

                J Offline
                J Offline
                Jun Du
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • J jpg 0

                  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.)

                  N Offline
                  N Offline
                  Nish Nishant
                  wrote on last edited by
                  #8

                  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)

                  1 Reply Last reply
                  0
                  • J jpg 0

                    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.)

                    J Offline
                    J Offline
                    Joe Woodbury
                    wrote on last edited by
                    #9

                    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

                    B 1 Reply Last reply
                    0
                    • J jpg 0

                      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.)

                      C Offline
                      C Offline
                      CCMint
                      wrote on last edited by
                      #10

                      I've used partial types to extend auto generated strongly typed datasets. Rather than having the designer re-generate your code and overwriting all your custom code you can separate your extended code into other .cs files.

                      1 Reply Last reply
                      0
                      • J Joe Woodbury

                        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

                        B Offline
                        B Offline
                        Brady Kelly
                        wrote on last edited by
                        #11

                        Yes, the potential for abuse is quite something, but I come across legit applications quite often.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups