What are some good alternatives to multiple-inheritance in .NET?

后端 未结 6 1437
梦如初夏
梦如初夏 2020-12-13 13:49

I\'ve run into a bit of a problem with my class hierarchy, in a WPF application. It\'s one of those issues where you have two inheritance trees merging together, and you can

6条回答
  •  孤城傲影
    2020-12-13 14:13

    I use mixins in such a case. mixins are a powerful concept used in many languages to add functionality to a class at runtime. mixins are well known in many languages. The re-mix framework is a framework that brings the mixin technology to .NET.

    The idea is simple: Decorate your class with a class attribute that represents a mixin. At runtime this functionality will be added to your class. So you can emulate multiple inheritance.

    The solution to your problem could be to make CustomizableObject to a mixin. You will need the re-mix framework for this.

    [Uses(CustomizableObjectMixin)] CustomizableControl : UserControl

    Please check out remix.codeplex.com for more details.

提交回复
热议问题