当前位置: 首页>>代码示例>>C#>>正文


C# System.Reflection.MethodInfo.Invoke方法代码示例

本文整理汇总了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 });
 }
开发者ID:cilliemalan,项目名称:Cargo,代码行数:4,代码来源:JsonContract.cs

示例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++)
//.........这里部分代码省略.........
开发者ID:DF-thangld,项目名称:web_game,代码行数:101,代码来源:IntrospectorTestCase.cs

示例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;
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:15,代码来源:ASTExpr.cs


注:本文中的System.Reflection.MethodInfo.Invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。