Skip to content

Make a class implementing an interface #92

Answered by svick
YBAZAN asked this question in Q&A
Discussion options

You must be logged in to vote

Hi.

That particular exception happens because usage of Type in aspects is limited. Instead, you have to use TypeFactory and work with IType.

The fundamental problem though, is that implementing an interface whose members have "unknown" types is currently not supported. The closest you can get right now is: (Try Metalama link)

public class ObjectHandler : MethodAspect
{
    public override void BuildAspect(IAspectBuilder<IMethod> builder)
    {
        base.BuildAspect(builder);

        var interfaceType =
            ((INamedType)TypeFactory.GetType(typeof(IHandleObject<>))).WithTypeArguments(builder.Target.Parameters.OfName("instance")!.Type);
        builder.Advice.ImplementInterface(b…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by svick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants