DEV Community

Szymon Hałucha
Szymon Hałucha

Posted on • Edited on

Default Interface Implementation or Mix-in design pattern in the C#

In a recent project I wrote, I needed to implement the traits or mix-in design pattern. The C# language has a built-in implementation of the traits pattern hiding under the name Default Interface Implementation, but it is in the experimental stage and is not compatible with the netstandard2.0 standard. For the purpose of this project, I created a simple package implementing the mix-in pattern, which is compatible with netstandard2.0 and C# 7.3+.

How to use it?

[Minerals.AutoMixins.AddMixin(typeof(ExampleMixin1), typeof(ExampleMixin2))]
public partial class ExampleClass
{
    // Implementation here...
}

[Minerals.AutoMixins.GenerateMixin]
public class ExampleMixin1
{
    // Implementation here...
}

[Minerals.AutoMixins.GenerateMixin]
public class ExampleMixin2
{
    // Implementation here...
}
Enter fullscreen mode Exit fullscreen mode

GitHub: https://github.com/SzymonHalucha/Minerals.AutoMixins
NugGet: https://www.nuget.org/packages/Minerals.AutoMixins/

Top comments (0)