相关疑难解决方法(0)

C#中的函数指针

我想在某些方面(或两者)DelegateMethodInfo有资格获得这个头衔.但是,它们都没有提供我正在寻找的语法上的好处.所以,简而言之,有什么方法可以写下面的内容:

FunctionPointer foo = // whatever, create the function pointer using mechanisms
foo();
Run Code Online (Sandbox Code Playgroud)

我不能使用可靠的委托(即,使用delegate关键字来声明委托类型),因为直到运行时才能知道确切的参数列表.作为参考,这里是我目前在LINQPad中使用的内容,B用户生成的代码将在哪里(因此)Main,因此对我的用户来说非常好,我试图删除.Call:

void Main()
{
    A foo = new B();
    foo["SomeFuntion"].Call();
}

// Define other methods and classes here
interface IFunction {
    void Call();
    void Call(params object[] parameters);
}

class A {
    private class Function : IFunction {
        private MethodInfo _mi;
        private A _this;
        public Function(A @this, MethodInfo mi) {
            _mi = mi;
            _this = @this; …
Run Code Online (Sandbox Code Playgroud)

c# reflection delegates

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

delegates ×1

reflection ×1