本文整理汇总了C#中System.Reflection.MethodInfo.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# System.Reflection.MethodInfo.Invoke方法的具体用法?C# System.Reflection.MethodInfo.Invoke怎么用?C# System.Reflection.MethodInfo.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了System.Reflection.MethodInfo.Invoke方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSerializationErrorCallback
internal static SerializationErrorCallback CreateSerializationErrorCallback(MethodInfo callbackMethodInfo)
{
return (o, context, econtext) => callbackMethodInfo.Invoke(o, new object[] { context, econtext });
}
示例2: runTest
public virtual void runTest()
{
MethodProvider mp = new MethodProvider();
try {
// Test boolean primitive.
System.Object[] booleanParams = new System.Object[]{true};
type = "boolean";
method = RuntimeSingleton.Introspector.getMethod(typeof(MethodProvider), type + "Method", booleanParams);
result = (System.String) method.Invoke(mp, (System.Object[]) booleanParams);
if (!result.Equals(type))
failures.add(type + "Method could not be found!");
// Test byte primitive.
System.Object[] byteParams = new System.Object[]{System.Byte.Parse("1")};
type = "byte";
method = RuntimeSingleton.Introspector.getMethod(typeof(MethodProvider), type + "Method", byteParams);
result = (System.String) method.Invoke(mp, (System.Object[]) byteParams);
if (!result.Equals(type))
failures.add(type + "Method could not be found!");
// Test char primitive.
System.Object[] characterParams = new System.Object[]{'a'};
type = "character";
method = RuntimeSingleton.Introspector.getMethod(typeof(MethodProvider), type + "Method", characterParams);
result = (System.String) method.Invoke(mp, (System.Object[]) characterParams);
if (!result.Equals(type))
failures.add(type + "Method could not be found!");
// Test double primitive.
System.Object[] doubleParams = new System.Object[]{(double) 1};
type = "double";
method = RuntimeSingleton.Introspector.getMethod(typeof(MethodProvider), type + "Method", doubleParams);
result = (System.String) method.Invoke(mp, (System.Object[]) doubleParams);
if (!result.Equals(type))
failures.add(type + "Method could not be found!");
// Test float primitive.
System.Object[] floatParams = new System.Object[]{(float) 1};
type = "float";
method = RuntimeSingleton.Introspector.getMethod(typeof(MethodProvider), type + "Method", floatParams);
result = (System.String) method.Invoke(mp, (System.Object[]) floatParams);
if (!result.Equals(type))
failures.add(type + "Method could not be found!");
// Test integer primitive.
System.Object[] integerParams = new System.Object[]{(int) 1};
type = "integer";
method = RuntimeSingleton.Introspector.getMethod(typeof(MethodProvider), type + "Method", integerParams);
result = (System.String) method.Invoke(mp, (System.Object[]) integerParams);
if (!result.Equals(type))
failures.add(type + "Method could not be found!");
// Test long primitive.
System.Object[] longParams = new System.Object[]{(long) 1};
type = "long";
method = RuntimeSingleton.Introspector.getMethod(typeof(MethodProvider), type + "Method", longParams);
result = (System.String) method.Invoke(mp, (System.Object[]) longParams);
if (!result.Equals(type))
failures.add(type + "Method could not be found!");
// Test short primitive.
System.Object[] shortParams = new System.Object[]{(short) 1};
type = "short";
method = RuntimeSingleton.Introspector.getMethod(typeof(MethodProvider), type + "Method", shortParams);
result = (System.String) method.Invoke(mp, (System.Object[]) shortParams);
if (!result.Equals(type))
failures.add(type + "Method could not be found!");
// Test untouchable
System.Object[] params_Renamed = new System.Object[]{};
method = RuntimeSingleton.Introspector.getMethod(typeof(MethodProvider), "untouchable", params_Renamed);
if (method != null)
failures.add(type + "able to access a private-access method.");
// Test really untouchable
method = RuntimeSingleton.Introspector.getMethod(typeof(MethodProvider), "reallyuntouchable", params_Renamed);
if (method != null)
failures.add(type + "able to access a default-access method.");
// There were any failures then show all the
// errors that occured.
int totalFailures = failures.size();
if (totalFailures > 0) {
System.Text.StringBuilder sb = new System.Text.StringBuilder("\nIntrospection Errors:\n");
for (int i = 0; i < totalFailures; i++)
//.........这里部分代码省略.........
示例3: GetMethodValue
private bool GetMethodValue(MethodInfo mi, PropertyLookupParams paramBag, ref object @value)
{
try
{
@value = mi.Invoke(paramBag.instance, (object[]) null);
return true;
}
catch (Exception ex)
{
paramBag.self.Error("Can't get property " + paramBag.lookupName
+ " using method get_/Get/Is/get/is as " + mi.Name + " from "
+ paramBag.prototype.FullName + " instance", ex);
}
return false;
}