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


C# TypeModel.DeepClone方法代码示例

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


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

示例1: DeepClone_ClassWithFields

		public void DeepClone_ClassWithFields(TypeModel model)
		{
			var classWithFields =
				new ClassWithFields(
					12,
					"lalala",
					new Guid("e0947b41-437a-4bda-8a47-16451417f307"),
					new ItemClass() { Message = "hello" },
					new List<int>() { 23, 45 },
					EnumTest.Item2,
					0.00000m,
					1.2345678m);

			var clone = (ClassWithFields)model.DeepClone(classWithFields);

			Assert.AreEqual(classWithFields.Guid, clone.Guid);
			Assert.AreEqual(classWithFields.Integer, clone.Integer);
			Assert.AreEqual(classWithFields.ItemClass.Message, clone.ItemClass.Message);
			Assert.AreEqual(classWithFields.List.Count, clone.List.Count);
			Assert.AreEqual(classWithFields.List[0], clone.List[0]);
			Assert.AreEqual(classWithFields.List[1], clone.List[1]);
			Assert.AreEqual(classWithFields.S, clone.S);
			Assert.AreEqual(classWithFields.EnumTest, clone.EnumTest);
			Assert.AreEqual(classWithFields._dec1, clone._dec1);
			Assert.AreEqual(classWithFields._dec2, clone._dec2);
		}
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:26,代码来源:Core_Fields.cs

示例2: DeepClone_FruitBag

		public void DeepClone_FruitBag(TypeModel model)
		{
			var fruitBag = new FruitBag()
			{
				Apple = new Apple()
				{
					Age = 12,
					StickerMessage = "13",
					Taste = 14
				},
				Color = 15,
				Pear = new Pear()
				{
					Age = 16,
					StickerMessage = "17",
					Hello = 18,
					Taste = 19
				}
			};

			var cloneFruitBag = (FruitBag)model.DeepClone(fruitBag);

			Assert.AreEqual(fruitBag.Apple.Age, cloneFruitBag.Apple.Age);
			Assert.AreEqual(fruitBag.Apple.StickerMessage, cloneFruitBag.Apple.StickerMessage);
			Assert.AreEqual(fruitBag.Apple.Taste, cloneFruitBag.Apple.Taste);

			Assert.AreEqual(fruitBag.Color, cloneFruitBag.Color);

			Assert.AreEqual(fruitBag.Pear.Age, cloneFruitBag.Pear.Age);
			Assert.AreEqual(fruitBag.Pear.StickerMessage, cloneFruitBag.Pear.StickerMessage);
			Assert.AreEqual(fruitBag.Pear.Hello, cloneFruitBag.Pear.Hello);
			Assert.AreEqual(fruitBag.Pear.Taste, cloneFruitBag.Pear.Taste);
		}
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:33,代码来源:Core_Container.cs

示例3: DeepClone_DictionaryStringToObjectContainer

		public void DeepClone_DictionaryStringToObjectContainer(TypeModel model)
		{
			var dictionary = new Dictionary<string, YellowPage>()
			                 	{
			                 		{ "A", new YellowPage() { Message = "Ahahaha" } },
			                 		{ "B", new YellowPage() { Message = "Blahblah" } },
			                 		{ "C", new YellowPage() { Message = "Caca" } },
			                 	};

			var yellowPages = new YellowPages()
			{
				Collection = dictionary,
				RefLink = dictionary
			};

			yellowPages.Collection.Add("D", new YellowPage() { Message = "Dannnnnnng!" });

			var cloneYellowPages = (YellowPages)model.DeepClone(yellowPages);

			Assert.AreEqual(yellowPages.Collection.Count, yellowPages.RefLink.Count);

			foreach (var key in yellowPages.Collection.Keys)
			{
				Assert.AreEqual(yellowPages.Collection[key].Message, cloneYellowPages.Collection[key].Message);
			}

			cloneYellowPages.Collection.Add("E", new YellowPage() { Message = "Ello without H" });
			Assert.AreEqual(cloneYellowPages.Collection.Count, cloneYellowPages.RefLink.Count);
		}
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:29,代码来源:Core_Container.cs

示例4: DeepClone_ClassWithFieldsRef_AsReference

		public void DeepClone_ClassWithFieldsRef_AsReference(TypeModel model)
		{
			var classWithFields = new ClassWithFieldsRef();
			var item = new ItemClass() { Message = "Hi there!" };
			classWithFields._item1 = item;
			classWithFields._item2 = item;
			var list = new List<int> { 2, 4, 5 };
			classWithFields._list1 = list;
			classWithFields._list2 = list;

			var clone = (ClassWithFieldsRef)model.DeepClone(classWithFields);

			Assert.AreEqual(classWithFields._item1.Message, clone._item1.Message);
			Assert.AreEqual(classWithFields._item2.Message, clone._item2.Message);

			Assert.AreEqual(classWithFields._list1.Count, clone._list1.Count);
			for (int i = 0; i < classWithFields._list1.Count; i++)
			{
				Assert.AreEqual(classWithFields._list1[i], clone._list1[i]);
			}

			Assert.AreEqual(classWithFields._list2.Count, clone._list2.Count);
			for (int i = 0; i < classWithFields._list2.Count; i++)
			{
				Assert.AreEqual(classWithFields._list2[i], clone._list2[i]);
			}

			Assert.IsTrue(object.ReferenceEquals(classWithFields._item1, classWithFields._item2));
			Assert.IsTrue(object.ReferenceEquals(classWithFields._list1, classWithFields._list2));
			Assert.IsTrue(object.ReferenceEquals(clone._item1, clone._item2));
			Assert.IsTrue(object.ReferenceEquals(clone._list1, clone._list2));
		}
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:32,代码来源:Core_Fields.cs

示例5: DeepClone_DictionaryOfClassRef_AsReference

		public void DeepClone_DictionaryOfClassRef_AsReference(TypeModel model)
		{
			var itemClass = new ItemClass() { Message = "hello"};

			var dictionary = new DictionaryOfClass()
			{
				Collection = new Dictionary<int, ItemClass>
				{
				    { 1, itemClass },   
					{ 2, itemClass }
				}
			};

			var clone = (DictionaryOfClass)model.DeepClone(dictionary);

			Assert.AreEqual(dictionary.Collection.Count, clone.Collection.Count);

			foreach (var key in dictionary.Collection.Keys)
			{
				Assert.AreEqual(dictionary.Collection[key].Message, clone.Collection[key].Message);
			}

			Assert.IsTrue(object.ReferenceEquals(dictionary.Collection[1], dictionary.Collection[2]), "Original reference failed");
			Assert.IsTrue(object.ReferenceEquals(clone.Collection[1], clone.Collection[2]), "Clone reference not maintained");
		}
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:25,代码来源:Core_Collection.cs

示例6: DeepCloneMaintainReference

		public void DeepCloneMaintainReference(TypeModel model)
		{
			var collection = new List<ItemClass>() { new ItemClass() { Message = "Hello" } };
			var itemClass = new ItemClass() { Message = "Haha" };

			var obj = new ComplexTestOfMaintainedReference()
			{
				Collection1 = collection,
				Collection2 = collection,
				Item1 = itemClass,
				Item2 = itemClass,
				Primitive1 = 1,
				Primitive2 = 2,
				String1 = "Test"
			};

			var clone = (ComplexTestOfMaintainedReference)model.DeepClone(obj);

			Assert.AreEqual(obj.Collection1.Count, clone.Collection1.Count);
			Assert.AreEqual(obj.Collection1[0].Message, clone.Collection1[0].Message);

			Assert.AreEqual(obj.Collection2.Count, clone.Collection2.Count);
			Assert.AreEqual(obj.Collection2[0].Message, clone.Collection2[0].Message);

			Assert.IsTrue(object.ReferenceEquals(clone.Collection1, clone.Collection2), "Collection reference");

			Assert.AreEqual(obj.Item1.Message, clone.Item1.Message);
			Assert.AreEqual(obj.Item2.Message, clone.Item2.Message);

			Assert.IsTrue(object.ReferenceEquals(clone.Item1, clone.Item2), "Item reference");

			Assert.AreEqual(obj.Primitive1, clone.Primitive1);
			Assert.AreEqual(obj.Primitive2, clone.Primitive2);
			Assert.AreEqual(obj.String1, clone.String1);
		}
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:35,代码来源:Core_AutoProperties.cs

示例7: Check

        void Check(TypeModel model)
        {
            
            var obj = Tuple.Create(
                123, new[] { Tuple.Create(1, 2, 3, 4, 5, 6, 7, new List<Tuple<float, float>> { Tuple.Create(1F,2F) }), Tuple.Create(9, 10, 11, 12, 13, 14, 15, new List<Tuple<float, float>> { Tuple.Create(3F,4F) }) }, true);

            var clone = (Tuple<int, Tuple<int, int, int, int, int, int, int, Tuple<List<Tuple<float, float>>>>[], bool>)model.DeepClone(obj);

            Assert.AreEqual(123, clone.Item1);
            Assert.AreEqual(2, clone.Item2.Length);
            Assert.AreEqual(1, clone.Item2[0].Item1);
            Assert.AreEqual(2, clone.Item2[0].Item2);
            Assert.AreEqual(3, clone.Item2[0].Item3);
            Assert.AreEqual(4, clone.Item2[0].Item4);
            Assert.AreEqual(5, clone.Item2[0].Item5);
            Assert.AreEqual(6, clone.Item2[0].Item6);
            Assert.AreEqual(7, clone.Item2[0].Item7);
            Assert.AreEqual(Tuple.Create(1F,2F), clone.Item2[0].Rest.Item1.Single());
            Assert.AreEqual(9, clone.Item2[1].Item1);
            Assert.AreEqual(10, clone.Item2[1].Item2);
            Assert.AreEqual(11, clone.Item2[1].Item3);
            Assert.AreEqual(12, clone.Item2[1].Item4);
            Assert.AreEqual(13, clone.Item2[1].Item5);
            Assert.AreEqual(14, clone.Item2[1].Item6);
            Assert.AreEqual(15, clone.Item2[1].Item7);
            Assert.AreEqual(Tuple.Create(3F, 4F), clone.Item2[1].Rest.Item1.Single());
            Assert.AreEqual(true, clone.Item3);
        }
开发者ID:GeorchW,项目名称:protobuf-net,代码行数:28,代码来源:Tuples.cs

示例8: CheckClone

 void CheckClone(TypeModel model, A original)
 {
     int sum = original.B.Data.Sum(x => x.Sum(b => (int)b));
     var clone = (A)model.DeepClone(original);
     Assert.IsInstanceOfType(typeof(A), clone);
     Assert.IsInstanceOfType(typeof(B), clone.B);
     Assert.AreEqual(sum, clone.B.Data.Sum(x => x.Sum(b => (int)b)));
 }
开发者ID:GeorchW,项目名称:protobuf-net,代码行数:8,代码来源:SO11317045.cs

示例9: DeepClone_NestedWithMultipleVisibility

		public void DeepClone_NestedWithMultipleVisibility(TypeModel model)
		{
			var obj = new Level1("1", 2, "3", "4", "5", new DateTime(2012, 05, 04), new ItemClass() { Message = "7" }, 8, 9, 10);

			var clone = (Level1)model.DeepClone(obj);

			Assert.AreEqual(obj.ToString(), clone.ToString());
		}
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:8,代码来源:Core_Nested.cs

示例10: TestMember

        private static void TestMember(TypeModel model)
        {
            var value = new Foo {Bar = new E[] {E.V0, E.V1, E.V2}};

            Assert.IsTrue(Program.CheckBytes(value, model, 0x18, 0x03, 0x18, 0x04, 0x18, 0x05));
            var clone = (Foo) model.DeepClone(value);
            Assert.AreEqual("V0,V1,V2", string.Join(",", clone.Bar), "clone");
        }
开发者ID:XewTurquish,项目名称:vsminecraft,代码行数:8,代码来源:Issue265.cs

示例11: Execute

 static void Execute(TypeModel model, string caption)
 {
     var orig = CreateData();
     var clone = (CanHazConcurrent)model.DeepClone(orig);
     Assert.AreNotEqual(clone, orig);
     
     TestData(clone, caption);
 }
开发者ID:Erguotou,项目名称:protobuf-net,代码行数:8,代码来源:Issue354.cs

示例12: Test

        private void Test(TypeModel model, string p)
        {
            var obj = Foo.Create(123);

            int oldCount = Count;
            var clone = (Foo)model.DeepClone(obj);
            int newCount = Count;
            Assert.AreEqual(oldCount + 1, newCount);
            Assert.AreEqual(123, clone.X);
        }
开发者ID:XewTurquish,项目名称:vsminecraft,代码行数:10,代码来源:SO14532116.cs

示例13: DeepClone_NestedGenericLevel1

		public void DeepClone_NestedGenericLevel1(TypeModel model)
		{
			var obj = new NestedClassTestsWrapper()
			{
				NestedGenericLevel1 = new NestedGenericLevel1<IItemClass>(new ItemClass() { Message = "Hello !" })
			};

			var clone = (NestedClassTestsWrapper)model.DeepClone(obj);

			Assert.AreEqual(obj.NestedGenericLevel1.ToString(), clone.NestedGenericLevel1.ToString());
		}
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:11,代码来源:Core_Nested.cs

示例14: Execute

        private static void Execute(TestUser obj, TypeModel model, string caption)
        {
            var ms = new MemoryStream();
            model.Serialize(ms, obj);
            Assert.Greater(2, 0, caption + ": I always get this wrong");
            Assert.Greater(ms.Length, 0, caption + ": Nothing was serialized");

            var clone = (TestUser) model.DeepClone(obj);
            Assert.AreEqual(0, clone.uid, caption + ": uid wasn't zero");
            Assert.IsTrue(clone.uidSpecified, caption + ": uid wasn't specified");
        }
开发者ID:XewTurquish,项目名称:vsminecraft,代码行数:11,代码来源:DetectMissing.cs

示例15: DeepClone_KeyValuePairAsField

		public void DeepClone_KeyValuePairAsField(TypeModel model)
		{
			var obj = new KeyValuePairWrapper()
			{
				Field = new KeyValuePair<int, ItemClass>(12, new ItemClass() { Message = "ABC" })
			};

			var clone = (KeyValuePairWrapper)model.DeepClone(obj);

			Assert.AreEqual(obj.Field.Key, clone.Field.Key);
			Assert.AreEqual(obj.Field.Value.Message, clone.Field.Value.Message);
		}
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:12,代码来源:Core_KeyValuePair.cs


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