using System; using System.Collections.Generic; using System.Text; using System.Reflection; namespace ScriptNET.Runtime { /// /// Binding to the method or constructor, also used for index getters /// internal class MethodBind : IObjectBind { MethodBase Method { get; set; } object Target { get; set; } object[] Arguments { get; set; } /// /// Creates binding to the method /// /// method or constructor to invoke /// method's owner or type if method is static /// a list of converted arguments that will be directly passed to the method public MethodBind(MethodBase method, object target, object[] arguments) { Method = method; Arguments = arguments; Target = target; } #region IInvokable Members public bool CanInvoke() { return Method != null; } /// /// /// /// /// Ignored for strongly bound objects (null should be passed) /// public object Invoke(IScriptContext context, object[] args) { //object result = RuntimeHost.NullValue; //if (args != null) //{ // if (Target == null && !Method.IsStatic) // result = Method.Invoke(args.First(), args.Skip(1).ToArray()); // else // result = Method.Invoke(Target, args); //} //else //{ // result = Method.Invoke(Target, Arguments); //} //context.Result = result; //return result; return Method.Invoke(Target, Arguments); } #endregion #if !PocketPC && !SILVERLIGHT //TODO: Review this approach public static implicit operator IntPtr(MethodBind invokableMethod) { return invokableMethod.Method.MethodHandle.GetFunctionPointer(); } #endif } }