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


C# Course.DeepClone方法代码示例

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


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

示例1: TestDeepClone_BasicTypes

        public void TestDeepClone_BasicTypes()
        {
            /*
            * Test primitive types + array type.
            */
            var pupil1 = new Pupil(1, "A", Gender.Male, new DateTime(2015, 01, 01));
            var course1 = new Course {Id = 1, Name = "C#"};

            course1.Pupils = new Pupil[] {pupil1};
            pupil1.Course = course1;

            var clonePupil1= pupil1.DeepClone();
            Assert.NotEqual(clonePupil1, pupil1);
            Assert.NotSame(clonePupil1, pupil1);
            Assert.True(Pupil.ValueEqual(pupil1, clonePupil1));

            var cloneCourse1 = course1.DeepClone();
            Assert.NotEqual(cloneCourse1, course1);
            Assert.NotSame(cloneCourse1, course1);

            Assert.NotEqual(cloneCourse1.Pupils, course1.Pupils);
            Assert.NotSame(cloneCourse1.Pupils, course1.Pupils);

            Assert.NotEqual(cloneCourse1.Pupils[0], course1.Pupils[0]);
            Assert.NotSame(cloneCourse1.Pupils[0], course1.Pupils[0]);
            Assert.True(Pupil.ValueEqual(cloneCourse1.Pupils[0], course1.Pupils[0]));

            Assert.Equal(course1.Pupils[0], pupil1);
            Assert.Same(course1.Pupils[0], pupil1);
            Assert.True(Pupil.ValueEqual(course1.Pupils[0], pupil1));
            Assert.NotEqual(cloneCourse1.Pupils[0], pupil1);
            Assert.NotSame(cloneCourse1.Pupils[0], pupil1);
            Assert.True(Pupil.ValueEqual(cloneCourse1.Pupils[0], pupil1));

            Assert.Same(course1.Pupils[0].Course, course1);
            Assert.NotSame(course1.Pupils[0].Course, cloneCourse1);
            Assert.Same(cloneCourse1.Pupils[0].Course, cloneCourse1);
        }
开发者ID:leevox,项目名称:sdk,代码行数:38,代码来源:CloneTest.cs


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