LokiMidgard / PartialMixins

Extends C# with Mixins.
MIT License
24 stars 2 forks source link

Allow MixinAttribute to be declared locally - so we don't need to reference Mixin.dll #7

Closed daiplusplus closed 3 years ago

daiplusplus commented 3 years ago

Overview

It's fairly commonplace for projects to reimplement common .NET types as internal to allow programmers to use modern C# language features while targeting older versions of .NET (e.g. you can use Extension Methods in C# 7.0 while still targeting .NET Framework 2.0 by declaring namespace System.Runtime.CompilerServices { internal class ExtensionAttribute : Attribute { ... } } ).

In a similar vein, I'd like to be able to use your PartialMixins tooling without my project needing to have a reference to PartialMixins.dll by having a private definition of the MixinAttribute.

So I'd be able to do something like this in a single file in my project:

using System;

namespace Mixins {
    internal class MixinAttribute : Attribute {
        public MixinAttribute( Type mixinType ) { }
    }
}

namespace MyProject
{
    internal class MyCommon
    {
        // etc
    }

    [Mixins.Mixin(typeof(MyCommon))]
    public partial class MySubject
    {
    }
}

Motivation:

Alternative solution:

Another possibility is allowing the fully-qualified name of the custom mixin attribute to be specified as an MSBuild property, e.g.:

<PropertyGroup>
    <MixinAttributeName>MyNamespace.MyMixinAttribute</MixinAttributeName>
</PropertyGroup>

The only requirement for a custom MixinAttribute is that it has a Type argument or property from which the mixin type can be inferred.

LokiMidgard commented 3 years ago

This could be done together with #5.