示例#1
0
        public static ObjectTypeHandle Marshal(object arg)
        {
            if (arg == null)
            {
                return(null);
            }
            ObjectTypeHandle handle = arg as ObjectTypeHandle;

            if (handle != null)
            {
                return(handle);
            }
            Type t = arg.GetType();

            if (t.IsDefined(TypeOf <MarshalByAddressAttribute> .TypeID, false))
            {
                return(new UnsafeHandle(arg));
            }
            Delegate del = arg as Delegate;

            if (del != null)
            {
                return(new DelegateAdapter(del));
            }
            Task task = arg as Task;

            if (task != null)
            {
                return(new TaskAdapter(task));
            }
            return(new ObjectTypeHandle(arg));
        }
示例#2
0
            public override object Invoke(__arglist)
            {
                ArgIterator ai = new ArgIterator(__arglist);

                ObjectTypeHandle[] args = new ObjectTypeHandle[ai.GetRemainingCount()];
                while (ai.GetRemainingCount() > 0)
                {
                    int    idx = args.Length - ai.GetRemainingCount();
                    object arg = TypedReference.ToObject(ai.GetNextArg());
                    args[idx] = AdapterTools.Marshal(arg);
                }
                var res = Delegate.InvokeMember("Invoke", ref args, new bool[args.Length]);

                ai = new ArgIterator(__arglist);
                while (ai.GetRemainingCount() > 0)
                {
                    int          idx = args.Length - ai.GetRemainingCount();
                    ObjectHandle arg = args[idx];
                    var          tr  = ai.GetNextArg();
                    if (__reftype(tr).IsByRef)
                    {
                        tr.SetValue(arg.Unwrap());
                    }
                }
                if (res != null)
                {
                    return(res.Unwrap());
                }
                else
                {
                    return(null);
                }
            }
示例#3
0
        public static object Call(StaticAdapter adapter, MethodBase method, params object[] args)
        {
            ObjectTypeHandle[] argHandles = Marshal(args);
            ObjectTypeHandle   resHandle  = adapter.InvokeMember(method, ref argHandles);

            Unmarshal(argHandles).CopyTo(args, 0);
            return(Unmarshal(resHandle));
        }
示例#4
0
 public static ObjectTypeHandle[] Marshal(params object[] args)
 {
     ObjectTypeHandle[] argHandles = new ObjectTypeHandle[args.Length];
     for (int i = 0; i < args.Length; i++)
     {
         argHandles[i] = Marshal(args[i]);
     }
     return(argHandles);
 }
示例#5
0
 public abstract void SetResult(ObjectTypeHandle result);