Where to put common interface methods when dealing with partial classes, inheritance, and Visual Studio Generated Code

前端 未结 2 1337
悲&欢浪女
悲&欢浪女 2021-01-16 21:20

Consider this situation:

We have two classes generated by Visual Studio, for example Typed Dataset Rows. These classes derive from a common base class which we can

相关标签:
2条回答
  • 2021-01-16 21:34

    It looks like the TableAdapter classes contained in .NET datasets has a base class that can be changed in teh designer. Is this the class you are using with partial classes, or could you use this as a way to provide a common base class where these methods could go?

    0 讨论(0)
  • 2021-01-16 21:35

    I would use encapsulation in this case. Create a class (with a private instance in both classes), and delegate the SomeMethod call to the internal, private class implementation.

    This eliminates (most) of the duplication, while still allowing the benefits of unique implementations per class as necessary.

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