コード例 #1
0
        public IAsyncResult BeginInvoke(Delegate method,
                                        object[] args)
        {
            GeneralDelegate x = Invoke;

            return(x.BeginInvoke(method, args, null, x));
        }
コード例 #2
0
 public void RemoveGD(int id, GeneralDelegate <T> gd)
 {
     if (!this.HasType(id))
     {
         return;
     }
     this._GDCntr[id] -= gd;
 }
コード例 #3
0
 public void AddGD(int id, GeneralDelegate <T> gd)
 {
     if (!this.HasType(id))
     {
         GeneralDelegate <T> generalDelegate = (GeneralDelegate <T>)null;
         this._GDCntr[id] = generalDelegate;
     }
     this._GDCntr[id] += gd;
 }
コード例 #4
0
        public void TestDelegateCast()
        {
            SpecializedDelegate specializedDelegate = new SpecializedDelegate(this.SpecializedDelegateMethod);
            GeneralDelegate generalDelegate = DuckTyping.Cast<GeneralDelegate>(specializedDelegate);
            Assert.IsTrue(generalDelegate.Target is IDuckProxy, "Cast did not return a delegate to a proxy.");
            Assert.AreEqual(specializedDelegate, ((IDuckProxy)(generalDelegate.Target)).UnwrapDuck(), "Cast returned a delegate to a proxy that does not refer to the original delegate.");
            Assert.AreEqual(specializedDelegate, DuckTyping.Cast<SpecializedDelegate>(generalDelegate), "Reverse cast returned the wrong value.");
            bool b = (bool)(generalDelegate("true"));

            generalDelegate = new GeneralDelegate(this.GeneralDelegateMethod);
            specializedDelegate = DuckTyping.Cast<SpecializedDelegate>(generalDelegate);
            Assert.IsTrue(specializedDelegate.Target is IDuckProxy, "Cast did not return a delegate to a proxy.");
            Assert.AreEqual(generalDelegate, ((IDuckProxy)(specializedDelegate.Target)).UnwrapDuck(), "Cast returned a delegate to a proxy that does not refer to the original delegate.");
            Assert.AreEqual(generalDelegate, DuckTyping.Cast<GeneralDelegate>(specializedDelegate), "Reverse cast returned the wrong value.");
            specializedDelegate("true");
        }
コード例 #5
0
        public void TestDelegateCast()
        {
            SpecializedDelegate specializedDelegate = new SpecializedDelegate(this.SpecializedDelegateMethod);
            GeneralDelegate     generalDelegate     = DuckTyping.Cast <GeneralDelegate>(specializedDelegate);

            Assert.IsTrue(generalDelegate.Target is IDuckProxy, "Cast did not return a delegate to a proxy.");
            Assert.AreEqual(specializedDelegate, ((IDuckProxy)(generalDelegate.Target)).UnwrapDuck(), "Cast returned a delegate to a proxy that does not refer to the original delegate.");
            Assert.AreEqual(specializedDelegate, DuckTyping.Cast <SpecializedDelegate>(generalDelegate), "Reverse cast returned the wrong value.");
            bool b = (bool)(generalDelegate("true"));

            generalDelegate     = new GeneralDelegate(this.GeneralDelegateMethod);
            specializedDelegate = DuckTyping.Cast <SpecializedDelegate>(generalDelegate);
            Assert.IsTrue(specializedDelegate.Target is IDuckProxy, "Cast did not return a delegate to a proxy.");
            Assert.AreEqual(generalDelegate, ((IDuckProxy)(specializedDelegate.Target)).UnwrapDuck(), "Cast returned a delegate to a proxy that does not refer to the original delegate.");
            Assert.AreEqual(generalDelegate, DuckTyping.Cast <GeneralDelegate>(specializedDelegate), "Reverse cast returned the wrong value.");
            specializedDelegate("true");
        }
コード例 #6
0
        public object EndInvoke(IAsyncResult result)
        {
            GeneralDelegate x = (GeneralDelegate)result.AsyncState;

            return(x.EndInvoke(result));
        }