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


C# MethodInfo.Invoke方法代码示例

本文整理汇总了C#中MethodInfo.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.Invoke方法的具体用法?C# MethodInfo.Invoke怎么用?C# MethodInfo.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MethodInfo的用法示例。


在下文中一共展示了MethodInfo.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunTest

	static bool RunTest (MethodInfo test)
	{
		Console.Write ("Running test {0, -25}", test.Name);
		try {
			Task t = test.Invoke (new Tester (), null) as Task;
			try {
				if (!Task.WaitAll (new[] { t }, 1000)) {
					Console.WriteLine ("FAILED (Timeout)");
					return false;
				}
			} catch (AggregateException) {
			}
			
			if (t.Status != TaskStatus.Faulted) {
				Console.WriteLine ("FAILED (Status={0})", t.Status);
				return false;
			}
			
			if (!(t.Exception.InnerException is ApplicationException)) {
				Console.WriteLine ("FAILED with wrong exception");
				return false;
			}
			
			Console.WriteLine ("OK");
			return true;
		} catch (Exception e) {
			Console.WriteLine ("FAILED");
			Console.WriteLine (e.ToString ());
			return false;
		}
	}
开发者ID:nobled,项目名称:mono,代码行数:31,代码来源:test-async-17.cs

示例2: Run

	public void Run (MethodInfo mi)
	{
		AddConversion (
			delegate (object from) {
				return mi.Invoke (null, new object [] { from });
			});
	}
开发者ID:mono,项目名称:gert,代码行数:7,代码来源:test.cs

示例3: RunTest

	static bool RunTest (MethodInfo test)
	{
		Console.Write ("Running test {0, -25}", test.Name);
		try {
			Task t = test.Invoke (new Tester (), null) as Task;
			if (!Task.WaitAll (new[] { t }, 1000)) {
				Console.WriteLine ("FAILED (Timeout)");
				return false;
			}

			var ti = t as Task<int>;
			if (ti != null) {
				if (ti.Result != 0) {
					Console.WriteLine ("FAILED (Result={0})", ti.Result);
					return false;
				}
			} else {
				var tb = t as Task<bool>;
				if (tb != null) {
					if (!tb.Result) {
						Console.WriteLine ("FAILED (Result={0})", tb.Result);
						return false;
					}
				}
			}

			Console.WriteLine ("OK");
			return true;
		} catch (Exception e) {
			Console.WriteLine ("FAILED");
			Console.WriteLine (e.ToString ());
			return false;
		}
	}
开发者ID:xzkmxd,项目名称:mono,代码行数:34,代码来源:test-async-16.cs

示例4: drawMethodGUI

    private void drawMethodGUI( int methodIndex, FunctionCallerAttribute attribute, MethodInfo methodInfo )
    {
        GUILayout.Space( 10 );

        if( _parameterDetailsDict.Count <= methodIndex )
            _parameterDetailsDict.Add( new Dictionary<string,object>() );
        var paramDict = _parameterDetailsDict[methodIndex];

        // draw the params
        foreach( var param in methodInfo.GetParameters() )
        {
            var paramKey = param.Name;

            if( !paramDict.ContainsKey( paramKey ) )
                paramDict.Add( paramKey, param.ParameterType.IsValueType ? System.Activator.CreateInstance( param.ParameterType ) : null );

            // add any supported types that you want here
            if( param.ParameterType == typeof( int ) )
                paramDict[paramKey] = EditorGUILayout.IntField( paramKey, (int)paramDict[paramKey] );
            else if( param.ParameterType == typeof( string ) )
                paramDict[paramKey] = EditorGUILayout.TextField( paramKey, (string)paramDict[paramKey] );
        }

        if( GUILayout.Button( attribute.buttonTitle ) )
        {
            var values = new object[paramDict.Count];
            paramDict.Values.CopyTo( values, 0 );
            methodInfo.Invoke( target, values );
        }
    }
开发者ID:ZeusbaseGameWorkshop,项目名称:ZeusbaseUNITY,代码行数:30,代码来源:AbstractFunctionCallerEditor.cs

示例5: Test

 static void Test(MethodInfo m)
 {
     try {
         m.Invoke(null, null);
         Console.WriteLine("PASS:" + m.Name);
     } catch (Exception ex) {
         Console.WriteLine("FAIL:" + m.Name + ": " + ex.InnerException.Message);
     }
 }
开发者ID:jontroncoso,项目名称:codetest,代码行数:9,代码来源:main.cs

示例6: RunTest

	static bool RunTest (MethodInfo test)
	{
		Console.Write ("Running test {0, -25}", test.Name);
		try {
			test.Invoke (new Tester (), null);
			Console.WriteLine ("OK");
			return true;
		} catch (Exception e) {
			Console.WriteLine ("FAILED");
			Console.WriteLine (e.InnerException.Message);
			return false;
		}
	}
开发者ID:nobled,项目名称:mono,代码行数:13,代码来源:dtest-error-01.cs

示例7: Start

	private void Start()
	{
		#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_4 || UNITY_5_5
		if(UseSkybox)
		{
			BindingFlags bfs = BindingFlags.NonPublic | BindingFlags.Static;
			getBuiltinExtraResourcesMethod = typeof( EditorGUIUtility ).GetMethod( "GetBuiltinExtraResource", bfs );
			UnityEngine.RenderSettings.skybox = (Material)getBuiltinExtraResourcesMethod.Invoke( null, new object[] { typeof( Material ), "Default-Skybox.mat" } );
		}
		#endif
		
		GameObject welcomeText = GameObject.Find("_____ute_____");

		if(welcomeText)
		{
			Destroy(welcomeText);
		}
		
		Application.runInBackground = RunInBackground;

		isConfirmingDeleteMap = false;
		isConfirmingDeletePattern = false;
		isConfirmingRenameMap = false;
		isConfirmingSaveAs = false;
		currentMapToDelete = "";
		currentPatternToDelete = "";
		newMapNameForRename = "";
		currentMapToRename = "";
		newMapNameForSaveAs = "";
		currentMapToSaveAs = "";
		isShowMenu = true;
		isShowMyPatterns = false;
		isShowMyMaps = true;
		newMapName = "myMap01";
		newPatternName = "myPattern01";
		ui = (GUISkin) Resources.Load("uteForEditor/uteUI");
		myMapsPath = AssetDatabase.GUIDToAssetPath(uteGLOBAL3dMapEditor.uteMyMapstxt);
		myPatternsPath = AssetDatabase.GUIDToAssetPath(uteGLOBAL3dMapEditor.uteMyPatternstxt);

		ReadAllMaps();
		ReadAllPatterns();
	}
开发者ID:gato0429,项目名称:GlobalGame2016,代码行数:42,代码来源:uteMenu.cs

示例8: AddHandlerForMethodInfo

    // NUNCA FAZER PROGRAMAÇÃO ORIENTADA À EXCEPÇÃO
    /*
    private void AddHandlerForMethodInfo(MethodInfo m) {
        try
        {
            Observer o = (Observer)Delegate.CreateDelegate(typeof(Observer), m);
            CounterEvent += o;
        }
        catch (ArgumentException e){}
    }
    */

    private void AddHandlerForMethodInfo(MethodInfo m)
    {
        ParameterInfo[] ps = m.GetParameters();
        if(m.ReturnType == typeof(void) && ps.Length == 1 && ps[0].ParameterType == typeof(int))
        {
            Object target = null;

            if (!m.IsStatic)
                target = Activator.CreateInstance(m.DeclaringType);

            // Opção 1: criar o delegate via reflexão
            // Observer o = (Observer)Delegate.CreateDelegate(typeof(Observer), target, m);

            // Opção 2: criação EXPLÍCITA do delegate para um método anónimo 
            // (resultante da Lambda) e chamada ao método via reflexão.
            Observer o = n => m.Invoke(target, new object[] { n });

            CounterEvent += o;
        }
    }
开发者ID:hmcaetano,项目名称:ave-2013-14-sem2,代码行数:32,代码来源:ObserverWithReflection.cs

示例9: CallReflectedCall

	static int CallReflectedCall (MethodInfo mi)
	{
		return (int) mi.Invoke (null, null);
	}
开发者ID:nobled,项目名称:mono,代码行数:4,代码来源:refcas4.cs

示例10: CreateAction

 Action CreateAction(MethodInfo inMethod)
 {
     return () => inMethod.Invoke(SROptions.Current, null);
 }
开发者ID:TrinketBen,项目名称:Courier,代码行数:4,代码来源:CheatManager.cs

示例11: Start

    void Start()
    {
        applyMethod = this.GetType().GetMethod("Apply" + auraType.ToString(), BindingFlags.NonPublic | BindingFlags.Instance);

        if (!infiniteDuration) {
          tickSpacing = (duration - initialDelay) * tickCount;
        }

        currentTime = 0.0f;
        currentTick = 0;

        // Apply the first effect if there is no initial delay
        if(initialDelay == 0f) {
          applyMethod.Invoke(this, null);
        }
    }
开发者ID:shawnmiller,项目名称:Capstone,代码行数:16,代码来源:Aura.cs

示例12: ExecuteCommand

    public void ExecuteCommand(String evaluatedCommand)
    {
        Debug.Log("Execute command: " + evaluatedCommand);
        Hashtable predArgs = Helper.ParsePredicate (evaluatedCommand);
        String pred = Helper.GetTopPredicate (evaluatedCommand);

        if (predArgs.Count > 0) {
            Queue<String> argsStrings = new Queue<String> (((String)predArgs [pred]).Split (new char[] { ',' }));
            List<object> objs = new List<object> ();

            while (argsStrings.Count > 0) {
                object arg = argsStrings.Dequeue ();

                if (Helper.v.IsMatch ((String)arg)) {	// if arg is vector form
                    objs.Add (Helper.ParsableToVector ((String)arg));
                }
                else if (arg is String) {	// if arg is String
                    Regex q = new Regex("\".*\"");
                    if (q.IsMatch (arg as String)) {
                        objs.Add (arg as String);
                    }
                    else {
                        List<GameObject> matches = new List<GameObject> ();
                        foreach (Voxeme voxeme in objSelector.allVoxemes) {
                            if (voxeme.voxml.Lex.Pred.Equals(arg)) {
                                matches.Add (voxeme.gameObject);
                            }
                        }

                        if (matches.Count <= 1) {
                            GameObject go = GameObject.Find (arg as String);
                            if (go == null) {
                                OutputHelper.PrintOutput (OutputController.Role.Affector,string.Format("What is a \"{0}\"?", (arg as String)));
                                return;	// abort
                            }
                            objs.Add (go);
                        }
                        else {
                            //Debug.Log (string.Format ("Which {0}?", (arg as String)));
                            //OutputHelper.PrintOutput (string.Format("Which {0}?", (arg as String)));
                        }
                    }
                }
            }

            objs.Add (true);
            methodToCall = preds.GetType ().GetMethod (pred.ToUpper());

            if ((methodToCall != null) &&  (preds.rdfTriples.Count > 0)) {
                Debug.Log ("ExecuteCommand: invoke " + methodToCall.Name);
                object obj = methodToCall.Invoke (preds, new object[]{ objs.ToArray () });
            }
        }
    }
开发者ID:nkrishnaswamy,项目名称:voxicon,代码行数:54,代码来源:EventManager.cs

示例13: EvaluateSkolemConstants

    public bool EvaluateSkolemConstants(EvaluationPass pass)
    {
        Hashtable temp = new Hashtable ();
        Regex regex = new Regex ([email protected]"[0-9]+");
        Match argsMatch;
        Hashtable predArgs;
        List<object> objs = new List<object>();
        Queue<String> argsStrings;
        bool doSkolemReplacement = false;
        Triple<String,String,String> replaceSkolems = null;

        foreach (DictionaryEntry kv in skolems) {
            objs.Clear ();
            if (kv.Value is String) {
                argsMatch = regex.Match ((String)kv.Value);
                if (argsMatch.Groups [0].Value.Length == 0) {	// matched an empty string = no match
                    Debug.Log (kv.Value);
                    predArgs = Helper.ParsePredicate ((String)kv.Value);
                    String pred = Helper.GetTopPredicate ((String)kv.Value);
                    if (((String)kv.Value).Count (f => f == '(') +	// make sure actually a predicate
                        ((String)kv.Value).Count (f => f == ')') >= 2) {
                        argsStrings = new Queue<String> (((String)predArgs [pred]).Split (new char[] {','}));
                        while (argsStrings.Count > 0) {
                            object arg = argsStrings.Dequeue ();

                            if (Helper.v.IsMatch ((String)arg)) {	// if arg is vector form
                                objs.Add (Helper.ParsableToVector ((String)arg));
                            }
                            else if (arg is String) {	// if arg is String
                                if ((arg as String).Count (f => f == '(') +	// not a predicate
                                    (arg as String).Count (f => f == ')') == 0) {
                                    if (preds.GetType ().GetMethod (pred.ToUpper ()).ReturnType != typeof(String)) {	// if predicate not going to return string (as in "AS")
                                        List<GameObject> matches = new List<GameObject> ();
                                        foreach (Voxeme voxeme in objSelector.allVoxemes) {
                                            if (voxeme.voxml.Lex.Pred.Equals(arg)) {
                                                matches.Add (voxeme.gameObject);
                                            }
                                        }

                                        if (matches.Count == 0) {
                                            GameObject go = GameObject.Find (arg as String);
                                            if (go == null) {
                                                OutputHelper.PrintOutput (OutputController.Role.Affector,string.Format("What is a \"{0}\"?", (arg as String)));
                                                return false;	// abort
                                            }
                                            objs.Add (go);
                                        }
                                        else if (matches.Count == 1) {
                                            GameObject go = matches[0];
                                            if (go == null) {
                                                OutputHelper.PrintOutput (OutputController.Role.Affector,string.Format("What is a \"{0}\"?", (arg as String)));
                                                return false;	// abort
                                            }
                                            objs.Add (go);
                                            doSkolemReplacement = true;
                                            replaceSkolems = new Triple<String,String,String> (kv.Key as String, arg as String, go.name);
                                            //skolems[kv] = go.name;
                                        }
                                        else {
                                            Debug.Log (string.Format ("Which {0}?", (arg as String)));
                                            OutputHelper.PrintOutput (OutputController.Role.Affector,string.Format("Which {0}?", (arg as String)));
                                            return false;	// abort
                                        }
                                    }
                                }

                                Regex q = new Regex("\".*\"");
                                if (q.IsMatch(arg as String)) {
                                    objs.Add (arg);
                                }
                                else {
                                    objs.Add (GameObject.Find (arg as String));
                                }
                            }
                        }

                        methodToCall = preds.GetType ().GetMethod (pred.ToUpper());

                        if (methodToCall == null) {
                            OutputHelper.PrintOutput (OutputController.Role.Affector,"Sorry, what does " + "\"" + pred + "\" mean?");
                            return false;
                        }

                        if ((methodToCall.ReturnType == typeof(String)) && (pass == EvaluationPass.Attributes)) {
                            Debug.Log ("EvaluateSkolemConstants: invoke " + methodToCall.Name);
                            object obj = methodToCall.Invoke (preds, new object[]{ objs.ToArray () });
                            Debug.Log (obj);

                            temp [kv.Key] = obj;
                        }
                        else if ((methodToCall.ReturnType == typeof(Vector3)) && (pass == EvaluationPass.RelationsAndFunctions)) {
                            Debug.Log ("EvaluateSkolemConstants: invoke " + methodToCall.Name);
                            object obj = methodToCall.Invoke (preds, new object[]{ objs.ToArray () });
                            Debug.Log (obj);

                            temp [kv.Key] = obj;
                        }
                    }
                }
                else {
//.........这里部分代码省略.........
开发者ID:nkrishnaswamy,项目名称:voxicon,代码行数:101,代码来源:EventManager.cs

示例14: InvokeAndEchoResult

	// Invokes the target method on the target object using the parameters supplied, and echoes the ToString of the result to the console.
	// Echoes nothing if the method is void.
	public static void InvokeAndEchoResult(MethodInfo targetMethod, object targetObject, object[] parameters) {
		if(targetMethod.ReturnType == typeof(void)) {
			targetMethod.Invoke(targetObject, parameters);
		} else {
			Echo(targetMethod.Invoke(targetObject, parameters).ToString());
		}

	}
开发者ID:wfowler1,项目名称:Miscellaneous-Soundboards,代码行数:10,代码来源:Console.cs

示例15: C3DxSensor

            /// <summary>
            /// constructor
            /// </summary>
            /// <param name="r3DxComSensor_p"></param>
            internal C3DxSensor(ref object r3DxComSensor_p)
            {
                s_oComSensor = r3DxComSensor_p;

                m_tyComSensor = s_oComSensor.GetType();
                //MethodInfo[] AllSensorMethods = m_tyComSensor.GetMethods();

                //Translation property
                s_miTranslation = m_tyComSensor.GetMethod("get_Translation");
                object result = s_miTranslation.Invoke(s_oComSensor, null);
                Type ty3DxVector = result.GetType();
                //MethodInfo[] TheMethods = ty3DxVector.GetMethods();
                s_miGetX = ty3DxVector.GetMethod("get_X");
                s_miGetY = ty3DxVector.GetMethod("get_Y");
                s_miGetZ = ty3DxVector.GetMethod("get_Z");

                //average time between two Sensor-Events when cap is moved
                MethodInfo Period = m_tyComSensor.GetMethod("get_Period");
                m_dPeriod = (double)Period.Invoke(s_oComSensor, null);

                //Rotation property
                //m_miRotation = m_tyComSensor.GetMethod("get_Rotation", new Type[0]);
                s_miRotation = m_tyComSensor.GetMethod("get_Rotation");
                result = s_miRotation.Invoke(s_oComSensor, null);
                Type ty3DxRotation = result.GetType();
                //TheMethods = ty3DxRotation.GetMethods();
                s_miRotGetX = ty3DxRotation.GetMethod("get_X");
                s_miRotGetY = ty3DxRotation.GetMethod("get_Y");
                s_miRotGetZ = ty3DxRotation.GetMethod("get_Z");
                s_miRotGetAngle = ty3DxRotation.GetMethod("get_Angle");

                SensorInput += new TDxSensorInputEvent(UpdateData);
            }
开发者ID:paladin74,项目名称:Dapple,代码行数:37,代码来源:TDxWWInput.cs


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