Skip to content
This repository was archived by the owner on Sep 4, 2024. It is now read-only.

Fix for TypeExtensionPoint in generic classes#115

Open
pleonex wants to merge 1 commit intomono:mainfrom
pleonex:fix-generics
Open

Fix for TypeExtensionPoint in generic classes#115
pleonex wants to merge 1 commit intomono:mainfrom
pleonex:fix-generics

Conversation

@pleonex
Copy link
Copy Markdown

@pleonex pleonex commented May 7, 2018

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
Copy link
Copy Markdown

dnfclas commented May 7, 2018

CLA assistant check
All CLA requirements met.

@Therzok
Copy link
Copy Markdown
Contributor

Therzok commented May 9, 2018

This LGTM. cc @slluis

Base automatically changed from master to main March 9, 2021 14:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants