public Value RuntimeInvoke (MethodMirror method, object target, Value[] values) { if (values != null) { // Some arguments may need to be boxed ParameterInfoMirror[] mparams = method.GetParameters (); if (mparams.Length != values.Length) throw new EvaluatorException ("Invalid number of arguments when calling: " + method.Name); for (int n=0; n<mparams.Length; n++) { TypeMirror tm = mparams [n].ParameterType; if (tm.IsValueType || tm.IsPrimitive) continue; object type = Adapter.GetValueType (this, values [n]); TypeMirror argTypeMirror = type as TypeMirror; Type argType = type as Type; if ((argTypeMirror != null && (argTypeMirror.IsValueType || argTypeMirror.IsPrimitive)) || (argType != null && (argType.IsValueType || argType.IsPrimitive))) { // A value type being assigned to a parameter which is not a value type. The value has to be boxed. try { values [n] = Thread.Domain.CreateBoxedValue (values [n]); } catch (NotSupportedException) { // This runtime doesn't support creating boxed values break; } } } } MethodCall mc = new MethodCall (this, method, target, values); Adapter.AsyncExecute (mc, Options.EvaluationTimeout); return mc.ReturnValue; }
bool CheckMethodParams (MethodMirror method, string[] paramTypes) { if (paramTypes == null) { // User supplied no params to match against, match anything we find. return true; } int i = 0; foreach (var param in method.GetParameters ()) { if (i == paramTypes.Length) { // This method has too many parameters... return false; } if (param.ParameterType.FullName != paramTypes[i] && param.ParameterType.CSharpName != paramTypes[i]) return false; i++; } return i == paramTypes.Length; }
public Value RuntimeInvoke (MethodMirror method, object target, Value[] values) { if (values != null) { // Some arguments may need to be boxed var mparams = method.GetParameters (); if (mparams.Length != values.Length) throw new EvaluatorException ("Invalid number of arguments when calling: " + method.Name); for (int n = 0; n < mparams.Length; n++) { var tm = mparams[n].ParameterType; if (tm.IsValueType || tm.IsPrimitive) continue; var type = Adapter.GetValueType (this, values[n]); var argTypeMirror = type as TypeMirror; var argType = type as Type; if (IsValueTypeOrPrimitive (argTypeMirror) || IsValueTypeOrPrimitive (argType)) { // A value type being assigned to a parameter which is not a value type. The value has to be boxed. try { values[n] = Thread.Domain.CreateBoxedValue (values [n]); } catch (NotSupportedException) { // This runtime doesn't support creating boxed values throw new EvaluatorException ("This runtime does not support creating boxed values."); } } } } if (!method.IsStatic && method.DeclaringType.IsClass && !IsValueTypeOrPrimitive (method.DeclaringType)) { object type = Adapter.GetValueType (this, target); var targetTypeMirror = type as TypeMirror; var targetType = type as Type; if ((target is StructMirror && ((StructMirror) target).Type != method.DeclaringType) || (IsValueTypeOrPrimitive (targetTypeMirror) || IsValueTypeOrPrimitive (targetType))) { // A value type being assigned to a parameter which is not a value type. The value has to be boxed. try { target = Thread.Domain.CreateBoxedValue ((Value) target); } catch (NotSupportedException) { // This runtime doesn't support creating boxed values throw new EvaluatorException ("This runtime does not support creating boxed values."); } } } try { return method.Evaluate (target is TypeMirror ? null : (Value) target, values); } catch (NotSupportedException) { AssertTargetInvokeAllowed (); var mc = new MethodCall (this, method, target, values); Adapter.AsyncExecute (mc, Options.EvaluationTimeout); return mc.ReturnValue; } }
string[] GetParamTypes (MethodMirror method) { List<string> paramTypes = new List<string> (); foreach (var param in method.GetParameters ()) paramTypes.Add (param.ParameterType.CSharpName); return paramTypes.ToArray (); }