Question

What are, exactly mixins?
Are there any techniques to achieve that in c#?

Was it helpful?

Solution

I'm no expert, but this is what I found.

  1. Mixins in C# 3.0
  2. Implementing Mixins with C# Extension Methods

From MSDN Blog:

Mixins In C#

Some suggest that extension methods in the upcoming C# 3.0 are a kind of Mixins, because you can put in functionalities in these methods and arbitrarily tag it onto any class you want. In the C# 2.0 specification section 20.1.3 it is clearly called out that the base class of a generic class has to be a constructed class type so this rules out using the above approach to be used in C#. I am not too sure on why we choose to explicitly disallow abstract subclass. Since C# does not support multiple-inheritance, IMO it should have supported Mixin style coding.

OTHER TIPS

A mixin is a set of class members that can be "mixed" into a class without the problems of multi-inheritance.

C# doesn't have mixins per-se, but offers Extension Methods for similar goals.

Please check out re-mix on codeplex.com. It is an open source library to bring mixins to .NET

There you will have a step by step guide on how to implement mixins with .NET

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top