示例#1
0
 private void ModifyEventSinkList(EventPump.ModifyEventSinkListType modificationType, EventSink eventSink)
 {
     lock (this.sinkListLock)
     {
         this.isModifyingEventSinkList = true;
         try
         {
             Dictionary <Guid, List <EventSink> > dictionary = this.eventSinks;
             if (modificationType == EventPump.ModifyEventSinkListType.AddEventSink)
             {
                 List <EventSink> collection = null;
                 List <EventSink> list;
                 if (dictionary.TryGetValue(eventSink.MailboxGuid, out collection))
                 {
                     list = new List <EventSink>(collection);
                 }
                 else
                 {
                     list = new List <EventSink>();
                 }
                 list.Add(eventSink);
                 Dictionary <Guid, List <EventSink> > dictionary2 = dictionary.ShallowCopy <Guid, List <EventSink> >();
                 dictionary2[eventSink.MailboxGuid] = list;
                 this.eventSinks = dictionary2;
                 if (this.exception != null)
                 {
                     eventSink.HandleException(this.exception);
                 }
             }
             else
             {
                 List <EventSink> collection2 = dictionary[eventSink.MailboxGuid];
                 List <EventSink> list2       = new List <EventSink>(collection2);
                 list2.Remove(eventSink);
                 Dictionary <Guid, List <EventSink> > dictionary3 = dictionary.ShallowCopy <Guid, List <EventSink> >();
                 if (list2.Count == 0)
                 {
                     dictionary3.Remove(eventSink.MailboxGuid);
                 }
                 else
                 {
                     dictionary3[eventSink.MailboxGuid] = list2;
                 }
                 this.eventSinks = dictionary3;
             }
         }
         finally
         {
             this.isModifyingEventSinkList = false;
         }
     }
 }
示例#2
0
文件: CopyTest.cs 项目: rexzh/RexToy
        public void CopyBySource()
        {
            var src = new Dictionary<string, string>();
            src["Age"] = "15";

            Sample.Person p = new Sample.Person();
            src.ShallowCopy(p, CopyOptions.BaseOnSource, false);

            Assert.AreEqual(15, p.Age);
        }
示例#3
0
文件: CopyTest.cs 项目: rexzh/RexToy
        public void CopyByDestWithError()
        {
            var src = new Dictionary<string, string>();
            src["Age"] = "15";

            Sample.Person p = new Sample.Person();
            src.ShallowCopy(p, CopyOptions.BaseOnDest, true);

            Assert.AreEqual(15, p.Age);
        }
示例#4
0
文件: CopyTest.cs 项目: rexzh/RexToy
        public void CopyByDestWithError()
        {
            var src = new Dictionary <string, string>();

            src["Age"] = "15";

            Sample.Person p = new Sample.Person();
            src.ShallowCopy(p, CopyOptions.BaseOnDest, true);

            Assert.AreEqual(15, p.Age);
        }
示例#5
0
文件: CopyTest.cs 项目: rexzh/RexToy
        public void CopyBySource()
        {
            var src = new Dictionary <string, string>();

            src["Age"] = "15";


            Sample.Person p = new Sample.Person();
            src.ShallowCopy(p, CopyOptions.BaseOnSource, false);

            Assert.AreEqual(15, p.Age);
        }
示例#6
0
文件: CopyTest.cs 项目: rexzh/RexToy
        public void CopyByBoth()
        {
            var src = new Dictionary<string, string>();
            src["Name"] = "r";
            src["Age"] = "15";

            Sample.Person p = new Sample.Person();
            src.ShallowCopy(p);

            Assert.AreEqual(15, p.Age);
            Assert.AreEqual("r", p.Name);
        }
        public void ShallowCopyTest()
        {
            var(str1, obj1) = ("obj1", new object());
            var(str2, obj2) = ("obj2", new object());
            var dict = new Dictionary <string, object>()
            {
                { str1, obj1 },
                { str2, obj2 }
            };
            var copyDict = dict.ShallowCopy();

            Assert.Same(obj1, copyDict[str1]);
            Assert.Same(obj2, copyDict[str2]);
        }
示例#8
0
文件: CopyTest.cs 项目: rexzh/RexToy
        public void CopyByBoth()
        {
            var src = new Dictionary <string, string>();

            src["Name"] = "r";
            src["Age"]  = "15";


            Sample.Person p = new Sample.Person();
            src.ShallowCopy(p);

            Assert.AreEqual(15, p.Age);
            Assert.AreEqual("r", p.Name);
        }