-
Notifications
You must be signed in to change notification settings - Fork 7
Mixin annotations options
Sagi edited this page Apr 9, 2015
·
3 revisions
NCop allows any combination of MixinsAttribute
attribute annotation as long as each implemented interface of the composite has a mixin implementation.
- Annotating the composite
public interface IDeveloper
{
void Code();
}
public interface IMusician
{
void Play();
}
public class GuitarPlayerMixin : IMusician
{
public void Play() {
Console.WriteLine("Playing C# accord with Fender Telecaster");
}
}
public class CSharpDeveloperMixin : IDeveloper
{
public void Code() {
Console.WriteLine("C# coding");
}
}
[TransientComposite]
[Mixins(typeof(CSharpDeveloperMixin), typeof(GuitarPlayerMixin))]
public interface IPerson : IDeveloper, IMusician
{
}
- Annotating the interfaces
[Mixins(typeof(CSharpDeveloperMixin))]
public interface IDeveloper
{
void Code();
[Mixins(typeof(GuitarPlayerMixin))]
public interface IMusician
{
void Play();
}
public class GuitarPlayerMixin : IMusician
{
public void Play() {
Console.WriteLine("Playing C# accord with Fender Telecaster");
}
}
public class CSharpDeveloperMixin : IDeveloper
{
public void Code() {
Console.WriteLine("C# coding");
}
}
[TransientComposite]
public interface IPerson : IDeveloper, IMusician
{
}
- Splitting the annotations
[Mixins(typeof(CSharpDeveloperMixin))]
public interface IDeveloper
{
void Code();
}
public interface IMusician
{
void Play();
}
public class GuitarPlayerMixin : IMusician
{
public void Play() {
Console.WriteLine("Playing C# accord with Fender Telecaster");
}
}
public class CSharpDeveloperMixin : IDeveloper
{
public void Code() {
Console.WriteLine("C# coding");
}
}
[TransientComposite]
[Mixins(typeof(GuitarPlayerMixin))]
public interface IPerson : IDeveloper, IMusician
{
}