Partial Classes in C#

后端 未结 20 2560
广开言路
广开言路 2021-02-19 08:25

Are there are good uses of Partial Classes outside the webforms/winforms generated code scenarios? Or is this feature basically to support that?

相关标签:
20条回答
  • 2021-02-19 09:01

    I often use partial classes to give each nested class its own file. There have been some architectures I've worked on where most of the implementation was only required by one class and so we nested those classes in that one class. It made sense to keep the files easier to maintain by using the partial class ability and splitting each one into its own file.

    We've also used them for grouping stock overrides or the hiding of a stock set of properties. Things like that. It's a handy way of mixing in a stock change (just copy the file and change the partial class name to the target class - as long as the target class is made partial too, of course).

    0 讨论(0)
  • 2021-02-19 09:03

    Correction, as Matt pointed out, both sides of the partial need to be in the same assembly. my bad.

    0 讨论(0)
提交回复
热议问题