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

RMAG news

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…
}

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

Leave a Reply

Your email address will not be published. Required fields are marked *