调用给它的类型名称和方法的名称为字符串的静态类中的方法 [英] Calling a method on a static class given it's type name and method names as strings

查看:102
本文介绍了调用给它的类型名称和方法的名称为字符串的静态类中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么可能去调用方法所给出的类​​名和方法名静态类,好吗?

How could I go about calling a method on a static class given the class name and the method name, please?

例如:

由于统环境 GetFolderPath ,我想使用反射调用 Environment.GetFolderPath()

Given System.Environment and GetFolderPath, I'd like to use Reflection to call Environment.GetFolderPath().

推荐答案

只是

Type.GetType(typeName).GetMethod(methodName).Invoke(null, arguments);

其中,的typeName 是类型为字符串的名称,方法名是方法作为名称字符串和参数是包含的参数来调用该方法的对象数组。

where typeName is the name of the type as a string, methodName is the name of the method as a string, and arguments is an array of objects containing the arguments to call the method with.

这篇关于调用给它的类型名称和方法的名称为字符串的静态类中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆