internal static object MethodCall(object o, MethodInfo mi, string[] tparams, ParameterInfo[] lpi) { List<object> passargs = new List<object>(); for (int i = 0; i < lpi.Count(); i++) passargs.Add(ChangeType(tparams[i], lpi[i].ParameterType)); try { o = mi.Invoke(o, passargs.ToArray()) ?? ""; } catch (Exception s) { return string.Format("Error " + s.Message); } return o; }
public object[] ArgsForParams(ParameterInfo [] prms) { object [] res = new object [prms.Length]; for (int i = 0; i < prms.Count (); i++) { try { res [i] = Convert.ChangeType (Arguments [i], prms [i].ParameterType); } catch (Exception e) { Console.Error.WriteLine ("Exception converting type: '{0}'.", prms [i].ParameterType); Console.Error.WriteLine (e); return null; } } return res; }
/// <summary> /// Builds a parameter list given a list of arguments and a list of parameter info /// </summary> /// <param name="args">A list of Values which will be distributed to the output lists</param> /// <param name="pi">An array of parameter info for the method</param> /// <param name="end">The end count</param> /// <param name="parameters">A parameters List to add to.</param> private static void BuildParameterList(FSharpList<Value> args, ParameterInfo[] pi, int end, List<List<object>> parameters) { //for a static method, the number of parameters //will equal the number of arguments on the node if (args.Count() == pi.Count()) { //ARGUMENT LOOP for (int j = 0; j < end; j++) { //create a list to hold each set of arguments var currParams = new List<object>(); //PARAMETER LOOP for (int i = 0; i < pi.Count(); i++) { var arg = args[i]; //if the value is a list, add the jth item converted //or the last item if i exceeds the count of the list if (arg.IsList) { var lst = (Value.List) arg; var argItem = (j < lst.Item.Count() ? lst.Item[j]: lst.Item.Last()); currParams.Add(DynamoTypeConverter.ConvertInput(argItem, pi[i].ParameterType)); } else //if the value is not a list, //just add the value currParams.Add(DynamoTypeConverter.ConvertInput(arg, pi[i].ParameterType)); } parameters.Add(currParams); } } //for instance methods, the first argument will be the //item or list of items which will be the target of invocation //in this case, skip parsing the first argument else { //ARGUMENT LOOP for (int j = 0; j < end; j++) { //create a list to hold each set of arguments var currParams = new List<object>(); //PARAMETER LOOP for (int i = 0; i < pi.Count(); i++) { var arg = args[i + 1]; //if the value is a list, add the jth item converted //or the last item if i exceeds the count of the list if (arg.IsList) { //var argItem = ((Value.List)arg).Item.Count() < end ? args.Last() : args[j]; var lst = (Value.List)arg; var argItem = (j < lst.Item.Count() ? lst.Item[j] : lst.Item.Last()); currParams.Add(DynamoTypeConverter.ConvertInput(argItem, pi[i].ParameterType)); } else //if the value is not a list, //just add the value currParams.Add(DynamoTypeConverter.ConvertInput(arg, pi[i].ParameterType)); } parameters.Add(currParams); } } }
private bool HasTwoParametersNeeded(ParameterInfo[] parameters, TypeInfo eventArgsType, TypeInfo extraPropertyType) { return parameters.Count() == 2 && HasOneParameterNeeded(parameters, eventArgsType) && ( extraPropertyType != null && parameters.ElementAt(1).ParameterType.GetTypeInfo().IsAssignableFrom(extraPropertyType) || parameters.ElementAt(1).ParameterType.GetTypeInfo().IsValueType == false ); }
/// <summary> /// Adds the by suffix. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="functionName">Name of the function.</param> /// <returns></returns> internal static string AddBySuffix(ParameterInfo[] parameters, string functionName) { int paramStart = 0; if (parameters.Count() > 0 && parameters.First().Name == "self") paramStart = 1; for (int paramIndex = paramStart; paramIndex < parameters.Length; paramIndex++) { ParameterInfo parameterInfo = parameters[paramIndex]; if (paramIndex == paramStart) functionName += "By_"; else functionName += "_"; functionName += parameterInfo.Name.ToLower().ToPascalCase(); } return functionName; }
private void TransformParametersIntoNameValueMapper(ParameterInfo[] methodParameters) { _parametersNameValueMapper = new Dictionary<int, string>(); for (var i = 0; i < methodParameters.Count(); i++) { _parametersNameValueMapper.Add(i, methodParameters[i].Name); } }
private static void InitializeRequestArray(ILGenerator generator, ParameterInfo[] methodParameters) { var singleArgumentParameters = methodParameters.Count(x => x.ParameterType != typeof(string[])); generator.Emit(OpCodes.Ldc_I4, singleArgumentParameters + 1); for (int i = 0; i < methodParameters.Length; i++) { if (methodParameters[i].ParameterType == typeof(string[])) { generator.Emit(OpCodes.Ldarg, i + 1); generator.Emit(OpCodes.Ldlen); generator.Emit(OpCodes.Conv_I4); generator.Emit(OpCodes.Add); } } generator.Emit(OpCodes.Newarr, typeof(string)); generator.Emit(OpCodes.Stloc_0); }
private void EmitMethodWithParameterCombo(int thissIdx, MethodInfo realMethod, Type[] parameters, MethodBuilder methodBuilder, ParameterInfo[] realParams) { var gen = methodBuilder.GetILGenerator(); if (!realMethod.IsStatic) { // Set 'this' to the result of JishProxy.GetInstance. This allows one // class to proxy to methods from different source classes. SetReferenceToAppropriateThis(gen, thissIdx); } for (int i = 0; i < parameters.Length; i++) { if (IsParamsArray(realParams[i])) { break; // Break as this is the last parameter (params must always be last) } // if (IsParamDelegate(realParams[i])) // TODO: This is in the wrong place // { // If the param is a delegate it needs to be replaced with a string which // will be used to find the 'real' delegate in the jish_internal scope. // } // Else add standard inline arg gen.Emit(OpCodes.Ldarg, i + 1); } for (int i = parameters.Count(); i < realParams.Length; i++) { if (IsParamsArray(realParams[i])) break; gen.Emit(OpCodes.Ldarg_0); gen.Emit(OpCodes.Ldc_I4, thissIdx); // Load the this index into the stack for GetInstance param gen.Emit(OpCodes.Ldc_I4, i); MethodInfo getLastOptional = typeof (JishProxy).GetMethod("GetOptionalParameterDefaultValue"); getLastOptional = getLastOptional.MakeGenericMethod(new[] {realParams[i].ParameterType}); gen.Emit(OpCodes.Callvirt, getLastOptional); } ParameterInfo last = realParams.Any() ? realParams.Last() : null; if (last != null && IsParamsArray(last)) { CovertRemainingParametersToArray(parameters, gen, realParams.Count() - 1, last.ParameterType.GetElementType()); } // Call the real method gen.Emit(realMethod.IsStatic ? OpCodes.Call : OpCodes.Callvirt, realMethod); gen.Emit(OpCodes.Ret); }