当前位置: 首页>>代码示例>>C#>>正文


C# DataItem.Unlink方法代码示例

本文整理汇总了C#中DataItem.Unlink方法的典型用法代码示例。如果您正苦于以下问题:C# DataItem.Unlink方法的具体用法?C# DataItem.Unlink怎么用?C# DataItem.Unlink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataItem的用法示例。


在下文中一共展示了DataItem.Unlink方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LinkAndUnlinkTwoDataItems

        public void LinkAndUnlinkTwoDataItems()
        {
            var dataObject1 = new CloneableClassWithThreeProperties();
            var dataObject2 = new CloneableClassWithThreeProperties();

            var dataItem1 = new DataItem(dataObject1, "a1");
            var dataItem2 = new DataItem(dataObject2, "a2");

            dataItem2.LinkTo(dataItem1);
            

            Assert.IsTrue(dataItem2.IsLinked);
            Assert.AreSame(dataItem1, dataItem2.LinkedTo);
            Assert.AreSame(dataItem2, dataItem1.LinkedBy[0]);

            dataItem2.Unlink();

            Assert.AreEqual(null, dataItem2.LinkedTo);
            Assert.AreEqual(0, dataItem1.LinkedBy.Count);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:20,代码来源:DataItemTest.cs

示例2: LinkAndUnlinkTwoDiscretizationItemsCheckValueAndName

        public void LinkAndUnlinkTwoDiscretizationItemsCheckValueAndName()
        {
            var grid1 = new Discretization { Name = "grid1" };
            var grid2 = new Discretization { Name = "grid2" };

            var dataItem1 = new DataItem(grid1, "a1");
            var dataItem2 = new DataItem(grid2, "a2");

            dataItem2.LinkTo(dataItem1);

            dataItem2.Unlink();

            Assert.AreEqual(typeof(Discretization), dataItem2.Value.GetType());
            Assert.AreEqual(typeof(Discretization), dataItem1.Value.GetType());

            var grid2X = (Discretization)dataItem2.Value;

            Assert.AreEqual("computational grid", grid2X.Name);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:19,代码来源:DataItemTest.cs

示例3: UnLinkEventIncludesPreviousValue

        public void UnLinkEventIncludesPreviousValue()
        {
            //old value is needed to close views.
            var linkedValue = new Url();
            var sourceDataItem = new DataItem(linkedValue);
            var targetDataItem = new DataItem(new Url());

            int callCount = 0;
            targetDataItem.Unlinked += (s, e) =>
            {
                callCount++;
                Assert.AreEqual(sourceDataItem, e.Source);
                Assert.AreEqual(targetDataItem, e.Target);
                Assert.AreEqual(linkedValue, e.PreviousValue);
            };
            targetDataItem.LinkTo(sourceDataItem);
            
            //action! unlink
            targetDataItem.Unlink();
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:20,代码来源:DataItemTest.cs

示例4: LinkAndUnlinkTwoDiscretizationItems

        public void LinkAndUnlinkTwoDiscretizationItems()
        {
            var dataObject1 = new Discretization();
            var dataObject2 = new Discretization();

            var dataItem1 = new DataItem(dataObject1, "a1");
            var dataItem2 = new DataItem(dataObject2, "a2");

            dataItem2.LinkTo(dataItem1);

            Assert.IsTrue(dataItem2.IsLinked);
            Assert.AreSame(dataItem1, dataItem2.LinkedTo);
            Assert.AreSame(dataItem2, dataItem1.LinkedBy[0]);

            dataItem2.Unlink();

            Assert.AreEqual(null, dataItem2.LinkedTo);
            Assert.AreEqual(0, dataItem1.LinkedBy.Count);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:19,代码来源:DataItemTest.cs

示例5: NameShouldChangeWhenLinkedNamedValueNameChanges

        public void NameShouldChangeWhenLinkedNamedValueNameChanges()
        {
            var dataObject1 = new CloneableClassWithThreeProperties();
            var dataObject2 = new CloneableClassWithThreeProperties();

            var dataItem1 = new DataItem(dataObject1, "name1");
            var dataItem2 = new DataItem(dataObject2, "name2");

            dataItem2.LinkTo(dataItem1);

            Assert.AreEqual("name1", dataItem1.Name);
            Assert.AreEqual("name2", dataItem2.Name);
            Assert.AreEqual("name1", ((INameable)dataItem1.Value).Name);
            Assert.AreEqual("name1", ((INameable)dataItem2.Value).Name);

            dataObject2.Name = "newName2";
            Assert.AreEqual("name1", ((INameable)dataItem1.Value).Name);
            Assert.AreEqual("name1", ((INameable)dataItem2.Value).Name);

            dataObject1.Name = "newName1";
            Assert.AreEqual("newName1", ((INameable)dataItem1.Value).Name);
            Assert.AreEqual("newName1", ((INameable)dataItem2.Value).Name);

            dataItem2.Unlink();

            // unlinking results in a new object of the original type as Value in the 
            // item with an uninitialized name. 
            // The original dataObject2 is now an orphan.
            Assert.AreEqual("newName1", ((INameable)dataItem1.Value).Name);
            Assert.AreEqual(null, ((INameable)dataItem2.Value).Name);

            ((INameable)dataItem2.Value).Name = "newerName2";
            Assert.AreEqual("newerName2", dataItem2.Name);

            dataItem2.Name = "weereensietsanders";
            Assert.AreEqual("weereensietsanders", ((INameable)dataItem2.Value).Name);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:37,代码来源:DataItemTest.cs


注:本文中的DataItem.Unlink方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。