如何通过反射调用一些没有任何参数和返回值的方法?
如何通过反射调用一些没有任何参数和返回值的方法?
这是MSDN 示例< /a>
// Define a class with a generic method.
public class Example
{
public static void Generic<T>()
{
Console.WriteLine("\r\nHere it is: {0}", "DONE");
}
}
那么 typeof(???) 中应该包含什么?
MethodInfo miConstructed = mi.MakeGenericMethod(typeof(???));
谢谢你!!!
How to call some method via Reflection without any parameters and any return values?
Here is MSDN sample
// Define a class with a generic method.
public class Example
{
public static void Generic<T>()
{
Console.WriteLine("\r\nHere it is: {0}", "DONE");
}
}
What should be within typeof(???) then?
MethodInfo miConstructed = mi.MakeGenericMethod(typeof(???));
Thank you!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您通过 C# 调用它,则需要提供一个类型,例如:
该要求不会改变;简而言之,该行将变为:
对于完整的、有效的说明:
If you were invoking that through C#, you would need to supply a type, for example:
that requirement does not change; simply, that line would become:
For a complete, working illustration:
在能够调用泛型方法之前,您需要指定其泛型参数。因此,您传递要用作通用参数的类型:
它应该打印:
Before being able to invoke a generic method you need to specify its generic argument(s). So you pass the type you want to be used as generic argument:
which should print: