예제 #1
0
    static int Clone(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        Delegate obj = LuaScriptMgr.GetNetObject <Delegate>(L, 1);
        object   o   = obj.Clone();

        LuaScriptMgr.PushVarObject(L, o);
        return(1);
    }
예제 #2
0
    private static int Clone(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        Delegate @delegate = (Delegate)LuaScriptMgr.GetNetObjectSelf(L, 1, "Delegate");
        object   o         = @delegate.Clone();

        LuaScriptMgr.PushVarObject(L, o);
        return(1);
    }
예제 #3
0
        public void CloneWorks()
        {
            var    sb = new StringBuilder();
            Action d1 = () => { sb.Append("1"); };
            Action d2 = (Action)Delegate.Clone(d1);

            Assert.IsFalse(d1 == d2);
            d2();
            Assert.AreEqual(sb.ToString(), "1");
        }
        public void Delegate()
        {
            Delegate inter = new Delegate(controller);

            inter.Name = "File";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller, "int");
            Parameter param = new Parameter(controller);

            param.Name     = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            Assert.That(inter.IsTheSame(inter.Clone(), ComparisonDepth.Outer), Is.True);
        }
        private void HandleDelegate(System.Windows.Forms.Control fromControl, System.Windows.Forms.Control toControl, bool removeExistDelegate)
        {
            Delegate existDelegate = this.GetDelegate(fromControl);

            if (existDelegate == null)
            {
                return;
            }

            this.EventInfo.AddEventHandler(toControl, ( Delegate )existDelegate.Clone());

            if (removeExistDelegate)
            {
                this.EventInfo.RemoveEventHandler(fromControl, existDelegate);
            }
        }
예제 #6
0
    private static int Clone(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            Delegate @delegate = (Delegate)ToLua.CheckObject(L, 1, typeof(Delegate));
            object   obj       = @delegate.Clone();
            ToLua.Push(L, obj);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
예제 #7
0
        public static object[] DetachEvents(object obj)
        {
            List <Delegate> evs = new List <Delegate>();

            FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            foreach (FieldInfo fi in fields)
            {
                if (fi.FieldType.IsSubclassOf(typeof(Delegate)))
                {
                    Delegate evh = (Delegate)fi.GetValue(obj);
                    if (evh != null)
                    {
                        evs.Add((Delegate)evh.Clone());
                    }
                    else
                    {
                        evs.Add(null);
                    }
                    Delegate.RemoveAll(evh, evh);
                }
            }
            return(evs.ToArray());
        }