mono / mono-addins

Mono.Addins is a generic framework for creating extensible applications, and for creating add-ins which extend those applications.
MIT License
163 stars 94 forks source link

Fix for TypeExtensionPoint in generic classes #115

Open pleonex opened 6 years ago

pleonex commented 6 years ago

This fix allows to have generic classes for plugins. For instance, the following interface will be the TypeExtensionPoint:

    [TypeExtensionPoint]
    public interface IConverter<in TSrc, out TDst>
    {
        TDst Convert(TSrc source);
    }

Then, we could have plugins implementing this class like:

    [Extension]
    public class Po2Binary : IConverter<Po, BinaryFormat>, IConverter<BinaryFormat, Po>
    {
        public BinaryFormat Convert(Po source)
        {
            // Implementation logic
        }

        public Po Convert(BinaryFormat source)
        {
            // Implementation logic
        }
    }

The problem was that the path variable contains the list of type names that the class implements. The types are separated by commas. In the case of generics, the type name contains also the list of types of the typeparam. for instance in this example, path contains:

Yarhl.FileFormat.IConverter`2[[Yarhl.FileFormat.BinaryFormat, Yarhl, Version=1.0.0.19273, Culture=neutral, PublicKeyToken=null],[Yarhl.Media.Text.Po, Yarhl.Media, Version=1.0.0.19273, Culture=neutral, PublicKeyToken=null]],Yarhl.FileFormat.IConverter`2[[Yarhl.Media.Text.Po, Yarhl.Media, Version=1.0.0.19273, Culture=neutral, PublicKeyToken=null],[Yarhl.FileFormat.BinaryFormat, Yarhl, Version=1.0.0.19273, Culture=neutral, PublicKeyToken=null]]

So if we just split by commas, we would get mix information with the generic types. Using the new approach we skip the information of the generic enclosed by [ ] so we get:

Yarhl.FileFormat.IConverter`2                                                                                                                                                                                
Yarhl.FileFormat.IConverter`2 
dnfclas commented 6 years ago

CLA assistant check
All CLA requirements met.

Therzok commented 6 years ago

This LGTM. cc @slluis