mercredi 4 août 2021

Mono.Cecil AddInterfaceImplementation equivalent?

I am working on Mono.Cecil codegen util, and I want to preform following operation:

Loop through types
If type contains X attribute:
- Add ITestInterface implementation (where ITestInterface has defined some methods)
// For reference

public interface ITestInterface
{
    void Something();
    int IntSomething();
}

// Expected result, if type contains X attribute:
// Before codegen:
[X]
public class CodeGenExample
{
}

// After codegen
[X]
public class CodeGenExample
{
   public void Something()
   {
       // some stuff
   }

   public int IntSomething()
   {
       // do some stuff
       return 0;
   }
}

I have seen that .NET Reflection has a AddInterfaceImplementation method (https://docs.microsoft.com/pl-pl/dotnet/api/system.reflection.emit.typebuilder.addinterfaceimplementation?view=net-5.0).

Is there a Mono.Cecil equivalent or a workaround for this & how to use it?





Aucun commentaire:

Enregistrer un commentaire