mercredi 19 août 2020

Call method that has a Delegate instance parameter through Reflection C#

I have this C# code in an external assembly:

namespace Fancy
{
  internal class Foo
  {
    public static void Window(string title, Foo.WindowFunction sceneViewFunc, int order)
    {}
    
    public delegate void WindowFunction(float x, float y);
  }
}

And I have my code:

class A 
{
  public static void Draw(float x, float y) 
  {
     // impl
  }

  static void Main(string[] args)
  {
     var newWindow = ?;
  }
}

I want to call Fancy.Foo.Window() like

Fancy.Foo.Window("Window Name", new Foo.WindowFunction(A.Draw), 450);

inside my A class through Reflection.

How can I do it? Tried lot of different options no success :/





Aucun commentaire:

Enregistrer un commentaire