Partial Classes in C#

2019-04-04 10:16发布

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

20条回答
ゆ 、 Hurt°
2楼-- · 2019-04-04 10:53

LINQ to SQL makes good use of partial classes to extend designer generated code. I think you will typically find this pattern of partial classes being used by designer-created code.

查看更多
地球回转人心会变
3楼-- · 2019-04-04 10:54

Where I'm at we have a program that handles incoming files from clients. It's set up so that each client's code is in it's own class library project, which knows how to handle whatever format that client chooses to use.

The main code uses the libraries by defining a fairly extensive interface that a class in the library must implement (probably should be a few distinct interfaces, but it's too late to change it now). Sometimes that involves a lot more code in the same class than we'd normally think prudent. Partial classes allow us to break them up somewhat.

查看更多
登录 后发表回答