public static AphidInteropFunctionAttribute Create(string name_s, bool value_b) { AphidInteropFunctionAttribute aphidInteropFunctionAttribute = new AphidInteropFunctionAttribute(name_s); aphidInteropFunctionAttribute.PassInterpreter = value_b; return(aphidInteropFunctionAttribute); // TODO: Edit factory method of AphidInteropFunctionAttribute // This method should be able to configure the object in all possible ways. // Add as many parameters as needed, // and assign their values to each field by using the API. }
public static AphidInteropFunction Create( AphidInteropFunctionAttribute attribute_aphidInteropFunctionAttribute, MethodInfo method_methodInfo ) { AphidInteropFunction aphidInteropFunction = new AphidInteropFunction (attribute_aphidInteropFunctionAttribute, method_methodInfo); return(aphidInteropFunction); // TODO: Edit factory method of AphidInteropFunction // This method should be able to configure the object in all possible ways. // Add as many parameters as needed, // and assign their values to each field by using the API. }
private void CreateInvokeDelegate(AphidInteropFunctionAttribute attribute, MethodInfo method) { var parameters = method.GetParameters(); var l = parameters.Length; if (l == 0) { #pragma warning disable IDE0045 // Convert to conditional expression if (!attribute.PassInterpreter) #pragma warning restore IDE0045 // Convert to conditional expression { InvokeDelegate = (callerScope, x) => method.Invoke(null, Array.Empty <object>()); } else { InvokeDelegate = (callerScope, x) => method.Invoke(null, new object[] { callerScope }); } } else if (!parameters[l - 1].IsDefined(typeof(ParamArrayAttribute))) { #pragma warning disable IDE0045 // Convert to conditional expression if (!attribute.PassInterpreter) #pragma warning restore IDE0045 // Convert to conditional expression { InvokeDelegate = (callerScope, x) => method.Invoke(null, x); } else { InvokeDelegate = (callerScope, x) => method.Invoke(null, PrefixScope(callerScope, x)); } } else { if (attribute.PassInterpreter) { l--; } InvokeDelegate = (callerScope, x) => { object[] parameters2; var argLen = x.Length; if (argLen < l) { if (attribute.PassInterpreter) { parameters2 = new object[argLen + 2]; parameters2[0] = callerScope; Array.Copy(x, 0, parameters2, 1, argLen); parameters2[argLen + 1] = Array.Empty <object>(); } else { parameters2 = new object[argLen + 1]; Array.Copy(x, parameters2, argLen); parameters2[argLen] = Array.Empty <object>(); } } else { if (attribute.PassInterpreter) { parameters2 = new object[l + 1]; parameters2[0] = callerScope; var stdParamCount = l - 1; Array.Copy(x, 0, parameters2, 1, stdParamCount); var paramArrayLen = argLen - stdParamCount; var paramArray = new object[paramArrayLen]; Array.Copy(x, stdParamCount, paramArray, 0, paramArrayLen); parameters2[stdParamCount + 1] = paramArray; } else { parameters2 = new object[l]; var stdParamCount = l - 1; Array.Copy(x, parameters2, stdParamCount); var paramArrayLen = argLen - stdParamCount; var paramArray = new object[paramArrayLen]; Array.Copy(x, stdParamCount, paramArray, 0, paramArrayLen); parameters2[stdParamCount] = paramArray; } } return(method.Invoke(null, parameters2)); }; } }