/// <summary> /// Executes the function. /// </summary> /// <param name="processor">The processor with context that called this functions.</param> /// <param name="caller">The calling object.</param> /// <param name="This">The "This" reference used in the call context.</param> /// <param name="parameters">The parameters used in this function call.</param> public SObject Call(ScriptProcessor processor, SObject caller, SObject This, SObject[] parameters) { var functionProcessor = new ScriptProcessor(processor.Context, processor.GetLineNumber()); SObject functionReturnObject; if (HasBuiltInMethod) { if (Method != null) { functionReturnObject = Method(functionProcessor, caller, This, parameters); } else { var dotNetParams = parameters.Select(ScriptOutAdapter.Translate); var dotNetReturnObj = DotNetMethod(ScriptOutAdapter.Translate(caller), new ScriptObjectLink(processor, caller), dotNetParams.ToArray()); functionReturnObject = ScriptInAdapter.Translate(processor, dotNetReturnObj); } } else { for (var i = 0; i < _parameters.Length; i++) { functionProcessor.Context.AddVariable(_parameters[i], parameters.Length > i ? parameters[i] : functionProcessor.Undefined); } functionProcessor.Context.This = This; functionReturnObject = functionProcessor.Run(Body); } return(functionReturnObject); }
/// <summary> /// Executes the function. /// </summary> /// <param name="processor">The processor with context that called this functions.</param> /// <param name="caller">The calling object.</param> /// <param name="This">The "This" reference used in the call context.</param> /// <param name="parameters">The parameters used in this function call.</param> public SObject Call(ScriptProcessor processor, SObject caller, SObject This, SObject[] parameters) { var functionProcessor = new ScriptProcessor(processor.Context, processor.GetLineNumber()); SObject functionReturnObject; if (HasBuiltInMethod) { if (Method != null) { functionReturnObject = Method(functionProcessor, caller, This, parameters); } else { var dotNetParams = parameters.Select(p => ScriptOutAdapter.Translate(p)); var dotNetReturnObj = DotNetMethod(ScriptOutAdapter.Translate(caller), new ScriptObjectLink(processor, caller), dotNetParams.ToArray()); functionReturnObject = ScriptInAdapter.Translate(processor, dotNetReturnObj); } } else { for (var i = 0; i < _parameters.Length; i++) { if (parameters.Length > i) { functionProcessor.Context.AddVariable(_parameters[i], parameters[i]); } else { functionProcessor.Context.AddVariable(_parameters[i], functionProcessor.Undefined); } } functionProcessor.Context.This = This; functionReturnObject = functionProcessor.Run(Body); } return functionReturnObject; }