本文整理汇总了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;
}
}
示例2: Run
public void Run (MethodInfo mi)
{
AddConversion (
delegate (object from) {
return mi.Invoke (null, new object [] { from });
});
}
示例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;
}
}
示例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 );
}
}
示例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);
}
}
示例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;
}
}
示例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();
}
示例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;
}
}
示例9: CallReflectedCall
static int CallReflectedCall (MethodInfo mi)
{
return (int) mi.Invoke (null, null);
}
示例10: CreateAction
Action CreateAction(MethodInfo inMethod)
{
return () => inMethod.Invoke(SROptions.Current, null);
}
示例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);
}
}
示例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 () });
}
}
}
示例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 {
//.........这里部分代码省略.........
示例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());
}
}
示例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);
}