Ai
1 Star 0 Fork 0

Alibaba Cloud/alibabacloud-console-bench-net-sdk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Helper.cs 2.24 KB
一键复制 编辑 原始数据 按行查看 历史
李振华 提交于 2020-12-15 10:51 +08:00 . .net sdk init
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace Aliyun.Acs.Core
{
public static class Helper
{
/// <summary>
/// 调用静态方法
/// </summary>
/// <param name="t">类全名</param>
/// <param name="strMethod">方法名</param>
/// <param name="aobjParams">参数表</param>
/// <returns>函数返回值</returns>
public static void RunStaticMethod(Type t, string strMethod, object[] aobjParams)
{
BindingFlags eFlags =
BindingFlags.Static | BindingFlags.Public |
BindingFlags.NonPublic;
RunMethod(t, strMethod, null, aobjParams, eFlags);
}
/// <summary>
/// 调用实例方法
/// </summary>
/// <param name="t">类全名</param>
/// <param name="strMethod">方法名</param>
/// <param name="objInstance">类的实例</param>
/// <param name="aobjParams">参数表</param>
///<returns>函数返回值</returns>
public static object RunInstanceMethod(Type t, string strMethod, object objInstance, object[] aobjParams)
{
BindingFlags eFlags = BindingFlags.Instance | BindingFlags.Public |
BindingFlags.NonPublic;
return RunMethod(t, strMethod,
objInstance, aobjParams, eFlags);
}
private static object RunMethod(Type t, string strMethod, object objInstance, object[] aobjParams,
BindingFlags eFlags)
{
MethodInfo m;
try
{
m = t.GetMethod(strMethod, eFlags);
if (m == null)
{
throw new ArgumentException("There is no method '" + strMethod + "' for type'" + t + "'.");
}
object objRet = m.Invoke(objInstance, aobjParams);
return objRet;
}
catch (TargetInvocationException ex)
{
if (null != ex.InnerException)
{
throw ex.InnerException;
}
throw;
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/aliyun/alibabacloud-console-bench-net-sdk.git
git@gitee.com:aliyun/alibabacloud-console-bench-net-sdk.git
aliyun
alibabacloud-console-bench-net-sdk
alibabacloud-console-bench-net-sdk
master

搜索帮助