相关疑难解决方法(0)

C#反射调用 - 类型'XXX'的对象无法转换为类型'System.Object []'

我创建了一个名为的实例input:

public class TestInput
{
    public int TesTInt { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我在这个函数中使用它:

public static class TestClass
{
    public static string TestFunction()
    {
        var testInput = new TestInput();
        string res = ServicesManager.Execute<string>((object) testInput);

        return res;
    }
}
Run Code Online (Sandbox Code Playgroud)

Execute功能是在这里:

public static OUT Execute<OUT>(object input) 
            where OUT : class
{
       var method = //getting method by reflection
       object[] arr = new object[] { input };
       return method.Invoke(null, arr) as OUT; //Error is triggered here
}
Run Code Online (Sandbox Code Playgroud)

我调用的方法是这样的:

public …
Run Code Online (Sandbox Code Playgroud)

c# reflection

0
推荐指数
1
解决办法
1987
查看次数

标签 统计

c# ×1

reflection ×1