public void CanCopyIntegers() { var original = 123; var result = CloneOperator.Clone(original); Assert.Equal(original, result); }
public void ClassCloneTest() { var model = new TestModel { B = "B", Model1 = new TestModel1("Model1"), Model2 = new TestModel2 { A = "A", B = 1 }, Self = new TestModel { B = "E" }, SelfList = new List <TestModel> { new TestModel { B = "l" } } }; var testModel = CloneOperator.Clone(model); Assert.NotSame(model, testModel); Assert.Equal(model.B, testModel.B); Assert.NotNull(model.Model1); Assert.NotSame(model.Model2, testModel.Model2); Assert.Equal(model.Model2.A, testModel.Model2.A); Assert.Equal(model.Model2.B, testModel.Model2.B); Assert.NotSame(model.Self, testModel.Self); Assert.Equal(model.Self.B, testModel.Self.B); Assert.NotSame(model.SelfList, testModel.SelfList); Assert.Equal(model.SelfList[0].B, testModel.SelfList[0].B); }
public void CanCopyStrings() { var original = "hello!"; var result = CloneOperator.Clone(original); Assert.Same(original, result); }
public void ClassCollectionArray() { FieldCloneClassCollectionModel model = new FieldCloneClassCollectionModel { Nodes = new List <FieldCloneNormalModel>() }; for (int i = 0; i < 10; i++) { model.Nodes.Add(new FieldCloneNormalModel() { Age = i, Name = i.ToString() }); } var newModel = CloneOperator.Clone(model); for (int i = 0; i < 10; i++) { Assert.Equal(model.Nodes[i].Name, newModel.Nodes[i].Name); Assert.Equal(model.Nodes[i].Age, newModel.Nodes[i].Age); Assert.NotEqual(i - 1, newModel.Nodes[i].Age); } model.Nodes.Clear(); Assert.NotEqual(model.Nodes.Count, newModel.Nodes.Count); }
public void ReadonlyNormal() { PropCloneNormalModel model = new PropCloneNormalModel { Age = 1000, Name = "ababab", Timer = DateTime.Now, money = 100000, Title = false, Id = 100000 }; var newModel = CloneOperator.Clone(model); Assert.False(newModel.NoUseCtor); Assert.Equal(0, newModel.ReadOnly); Assert.Equal(model.ReadOnlyString, newModel.ReadOnlyString); Assert.Equal(model.ReadOnlyString1, newModel.ReadOnlyString1); Assert.Equal(model.Id, newModel.Id); Assert.Equal(model.Title, newModel.Title); Assert.Equal(model.money, newModel.money); Assert.Equal(model.Timer, newModel.Timer); Assert.Equal(model.Age, newModel.Age); Assert.Equal(model.Name, newModel.Name); }
public void PropClassCollectionArray2() { CloneCollectionModel model = new CloneCollectionModel { LANodes = new List <PropCloneNormalModel[]>() }; for (int i = 0; i < 5; i++) { model.LANodes.Add(new PropCloneNormalModel[10]); for (int j = 0; j < 10; j++) { model.LANodes[i][j] = new PropCloneNormalModel() { Age = j, Name = j.ToString() }; } } var newModel = CloneOperator.Clone(model); for (int i = 0; i < 5; i++) { Assert.NotEqual(model.LANodes, newModel.LANodes); for (int j = 0; j < 10; j++) { Assert.NotEqual(model.LANodes[i], newModel.LANodes[i]); Assert.Equal(model.LANodes[i][j].Name, newModel.LANodes[i][j].Name); Assert.Equal(model.LANodes[i][j].Age, newModel.LANodes[i][j].Age); } } }
public void PropClassCollectionArray1() { CloneCollectionModel model = new CloneCollectionModel(); var INodes = new List <List <PropCloneNormalModel> >(); for (int i = 0; i < 5; i++) { INodes.Add(new List <PropCloneNormalModel>()); for (int j = 0; j < 10; j++) { INodes[i].Add(new PropCloneNormalModel() { Age = j, Name = j.ToString() }); } } model.LLNodes = INodes; var newModel = CloneOperator.Clone(model); Assert.NotEqual(model.LLNodes, newModel.LLNodes); var oldNodes = new List <List <PropCloneNormalModel> >(model.LLNodes); var newNodes = new List <List <PropCloneNormalModel> >(newModel.LLNodes); for (int i = 0; i < 5; i++) { for (int j = 0; j < 10; j++) { Assert.NotEqual(oldNodes[i], newNodes[i]); Assert.Equal(oldNodes[i][j].Name, newNodes[i][j].Name); Assert.Equal(oldNodes[i][j].Age, newNodes[i][j].Age); } } }
public void CloneLinkTest() { FieldLinkModel model = new FieldLinkModel(); model.Nodes.AddFirst(new FieldLinkModel() { Name = "1", Age = 1 }); model.Nodes.AddLast(new FieldLinkModel() { Name = "2", Age = 2 }); var newModel = CloneOperator.Clone(model); newModel.Nodes = CloneOperator.Clone(model.Nodes); Assert.NotEqual(model.Nodes.First, newModel.Nodes.First); Assert.Equal(model.Nodes.First.Value.Name, newModel.Nodes.First.Value.Name); Assert.NotEqual(model.Nodes.First.Next, newModel.Nodes.First.Next); Assert.Equal(model.Nodes.First.Next.Value.Name, newModel.Nodes.First.Next.Value.Name); }
public void CloneArraySelfTest() { FieldSelfLinkArrayModel model = new FieldSelfLinkArrayModel() { Name = "1", Age = 1 }; model.Next = new FieldSelfLinkArrayModel[5]; for (int i = 0; i < 5; i++) { model.Next[i] = new FieldSelfLinkArrayModel() { Name = i.ToString(), Age = i }; } var newModel = CloneOperator.Clone(model); Assert.NotEqual(model.Next, newModel.Next); for (int i = 0; i < 5; i++) { Assert.NotEqual(model.Next[i], newModel.Next[i]); Assert.Equal(model.Next[i].Name, newModel.Next[i].Name); } }
public void ClassCloneTest() { List <string> lli = new List <string>(); lli.Add("123"); lli.Add("456"); var tt1 = CloneOperator.Clone(lli.ToArray()); Assert.NotSame(lli, tt1); for (int i = 0; i < lli.Count; i++) { Assert.Equal(tt1[i], tt1[i]); } List <TestList> kk = new List <TestList>(); TestList t1 = new TestList(); t1.B = "13"; TestList2 t2 = new TestList2(); t2.A = "234"; t1.List2 = t2; kk.Add(t1); //var ttt1 = CloneOperator.Clone(kk); var testList2 = CloneOperator.Clone(t1); // 实体拷贝时出错 var tt = CloneOperator.Clone(lli); //Console.WriteLine(tt == null); }
public void DictionaryCloneTest() { var dict = new Dictionary <string, List <int> >() { { "1", new List <int> { 1 } } }; var dictNew = CloneOperator.Clone(dict); Assert.NotNull(dictNew); Assert.NotSame(dict, dictNew); Assert.True(dict.Count == dictNew.Count); Assert.NotNull(dictNew["1"]); Assert.NotSame(dict["1"], dictNew["1"]); var dictModel = new Dictionary <TestModel, int> { { new TestModel(), 1 } }; var dictModelNew = CloneOperator.Clone(dictModel); Assert.NotNull(dictModelNew); Assert.NotSame(dictModel, dictModelNew); Assert.True(dictModel.Count == dictModelNew.Count); Assert.NotNull(dictModelNew.Keys); Assert.NotSame(dictModel.Keys.FirstOrDefault(), dictModelNew.Keys.FirstOrDefault()); }
private async Task StartAsync(IConfiguration configuration) { var a = CloneOperator.Clone((ConfigurationRoot)configuration); Log.Logger.Information("DataSync starts job"); await PreHandlerAsync(a); }
public void CanCopyArrays() { var original = new object[] { 123, "hello!" }; var result = CloneOperator.Clone(original); Assert.Equal(original, result); Assert.NotSame(original, result); }
static void Main(string[] args) { /* * 在此之前,你需要右键,选择工程文件,在你的.csproj里面 * * 写上这样一句浪漫的话: * * <PreserveCompilationContext>true</PreserveCompilationContext> */ string text = @"namespace HelloWorld { public class Test { public Test(){ Name=""111""; } public string Name; public int Age{get;set;} } }"; //根据脚本创建动态类 Type type = ClassBuilder.GetType(text); //创建动态类实例代理 DynamicOperator instance = type; if (instance["Name"].StringValue == "111") { //调用动态委托赋值 instance["Name"].StringValue = "222"; } //调用动态类 Console.WriteLine(instance["Name"].StringValue); TestB b = new TestB(); b.Name = "abc"; var result = CloneOperator.Clone(b); //创建动态类实例代理 DynamicOperator <TestB> instance2 = new DynamicOperator <TestB>(); if (instance2["Name"].StringValue == "111") { //调用动态委托赋值 instance2["Name"].StringValue = "222"; } //调用动态类 Console.WriteLine(instance2["Name"].StringValue); Console.ReadKey(); }
public void RegressionTest_20() { var original = new Dictionary <int, Component>() { { 1, new Component() }, }; var result = CloneOperator.Clone(original); GC.GetTotalMemory(true); // force full GC }
public void CloneDictionaryArrayTest() { CloneDictArrayModel model = new CloneDictArrayModel { Dicts = new Dictionary <string, FieldCloneNormalModel[]> [5] }; for (int i = 0; i < 5; i++) { model.Dicts[i] = new Dictionary <string, FieldCloneNormalModel[]>(); for (int j = 0; j < 5; j++) { model.Dicts[i][j.ToString()] = new FieldCloneNormalModel[5]; for (int z = 0; z < 5; z++) { model.Dicts[i][j.ToString()][z] = new FieldCloneNormalModel { Age = 1000, Name = "ababab1", Timer = DateTime.Now, money = 100000, Flag = CloneEnum.B, Title = true, Id = 0 }; } } } var newModel = CloneOperator.Clone(model); for (int i = 0; i < 5; i++) { Assert.Equal(model.Dicts[i].Count, newModel.Dicts[i].Count); for (int j = 0; j < 5; j++) { Assert.Equal(model.Dicts[i][j.ToString()].Length, newModel.Dicts[i][j.ToString()].Length); for (int z = 0; z < 5; z++) { Assert.Equal(model.Dicts[i][j.ToString()][z].Name, newModel.Dicts[i][j.ToString()][z].Name); Assert.Equal(model.Dicts[i][j.ToString()][z].Age, newModel.Dicts[i][j.ToString()][z].Age); Assert.Equal(model.Dicts[i][j.ToString()][z].Flag, newModel.Dicts[i][j.ToString()][z].Flag); Assert.Equal(model.Dicts[i][j.ToString()][z].Id, newModel.Dicts[i][j.ToString()][z].Id); Assert.Equal(model.Dicts[i][j.ToString()][z].Timer, newModel.Dicts[i][j.ToString()][z].Timer); Assert.Equal(model.Dicts[i][j.ToString()][z].Title, newModel.Dicts[i][j.ToString()][z].Title); } model.Dicts[i][j.ToString()] = new FieldCloneNormalModel[0]; Assert.NotEqual(model.Dicts[i][j.ToString()].Length, newModel.Dicts[i][j.ToString()].Length); } model.Dicts[i].Clear(); Assert.NotSame(model.Dicts[i], newModel.Dicts[i]); Assert.NotEqual(model.Dicts[i].Count, newModel.Dicts[i].Count); } }
public void CanCopyInterfaceField() { PocoWithInterface original = new PocoWithInterface(); original.Collection.Add("A"); var result = CloneOperator.Clone(original); Assert.NotSame(original, result); Assert.NotSame(original.Collection, result.Collection); }
public void ListOfSimpleClassDifferentInstances_DeepCopy() { var clone = CloneOperator.Clone(this._listOfSimpleClassDifferentInstances); Assert.NotSame(clone, this._listOfSimpleClassDifferentInstances); var firstInstance = clone[0]; for (int i = 1; i < clone.Count; i++) { Assert.NotSame(firstInstance, clone[i]); } }
public void Clone1DimWithSimple() { string[] arrIns0 = null; var arrIns1 = new sbyte[] { 1, 2, 3, sbyte.MinValue, sbyte.MaxValue }; var arrIns2 = new short[] { 4, 5, 6, short.MinValue, short.MaxValue }; var arrIns3 = new int[] { 7, -8, 9, -10, int.MinValue, int.MaxValue }; var arrIns4 = new long[] { 12345, 23456, long.MinValue, long.MaxValue }; var arrIns5 = new byte[] { 123, 234, 56, byte.MinValue, byte.MaxValue }; var arrIns6 = new ushort[] { 123, 567, ushort.MinValue, ushort.MaxValue }; var arrIns7 = new uint[] { 678, 349, uint.MinValue, uint.MaxValue }; var arrIns8 = new ulong[] { 789, 2345, ulong.MinValue, ulong.MaxValue }; var arrIns9 = new float[] { 678.234F, 789, 234.000F, float.MinValue, float.MaxValue }; var arrIns10 = new double[] { 567, 678.56789, double.MinValue, double.MaxValue }; var arrIns11 = new decimal[] { 45678, 678.00M, 56789.234M, decimal.MinValue, decimal.MaxValue }; var arrIns12 = new GenderEnum[] { GenderEnum.Female, GenderEnum.Secrecy }; var arrIns13 = new bool[] { true, false, true }; var arrIns14 = new char[] { '1', '2', 'a', 'Z' }; var arrIns15 = new string[] { "Vito", "AzulX", "guodf", "wxn401", "myFirstway" }; var arrIns0_Clone = CloneOperator.Clone(arrIns0); var arrIns1_Clone = CloneOperator.Clone(arrIns1); var arrIns2_Clone = CloneOperator.Clone(arrIns2); var arrIns3_Clone = CloneOperator.Clone(arrIns3); var arrIns4_Clone = CloneOperator.Clone(arrIns4); var arrIns5_Clone = CloneOperator.Clone(arrIns5); var arrIns6_Clone = CloneOperator.Clone(arrIns6); var arrIns7_Clone = CloneOperator.Clone(arrIns7); var arrIns8_Clone = CloneOperator.Clone(arrIns8); var arrIns9_Clone = CloneOperator.Clone(arrIns9); var arrIns10_Clone = CloneOperator.Clone(arrIns10); var arrIns11_Clone = CloneOperator.Clone(arrIns11); var arrIns12_Clone = CloneOperator.Clone(arrIns12); var arrIns13_Clone = CloneOperator.Clone(arrIns13); var arrIns14_Clone = CloneOperator.Clone(arrIns14); var arrIns15_Clone = CloneOperator.Clone(arrIns15); Assert.Equal(arrIns0_Clone, arrIns0); Assert.Equal(arrIns1_Clone, arrIns1); Assert.Equal(arrIns2_Clone, arrIns2); Assert.Equal(arrIns3_Clone, arrIns3); Assert.Equal(arrIns4_Clone, arrIns4); Assert.Equal(arrIns5_Clone, arrIns5); Assert.Equal(arrIns6_Clone, arrIns6); Assert.Equal(arrIns7_Clone, arrIns7); Assert.Equal(arrIns8_Clone, arrIns8); Assert.Equal(arrIns9_Clone, arrIns9); Assert.Equal(arrIns10_Clone, arrIns10); Assert.Equal(arrIns11_Clone, arrIns11); Assert.Equal(arrIns12_Clone, arrIns12); Assert.Equal(arrIns13_Clone, arrIns13); Assert.Equal(arrIns14_Clone, arrIns14); Assert.Equal(arrIns15_Clone, arrIns15); }
public void ListOfSimpleClassSameInstance_DeepCopy() { var clone = CloneOperator.Clone(this._listOfSimpleClassSameInstance); Assert.NotSame(clone, this._listOfSimpleClassSameInstance); var firstInstance = clone[0]; for (int i = 1; i < clone.Count; i++) { Assert.NotSame(firstInstance, clone[i]); Assert.Equal(firstInstance.String, clone[i].String); } }
public void SubClassArray() { FieldCloneSubNodeModel model = new FieldCloneSubNodeModel(); model.Node = new FieldCloneNormalModel() { Age = 1, Name = "111" }; var newModel = CloneOperator.Clone(model); Assert.Equal(model.Node.Name, newModel.Node.Name); Assert.Equal(model.Node.Age, newModel.Node.Age); }
public void ClassInnerTest() { TestModel.InnerClass model = new TestModel.InnerClass(); model.Name = "abc"; model.SelfList = new List <TestModel> { new TestModel { B = "l" } }; var testModel = CloneOperator.Clone(model); Assert.NotSame(model, testModel); Assert.NotSame(model.SelfList, testModel.SelfList); Assert.Equal(model.SelfList[0].B, testModel.SelfList[0].B); }
public void CloneDictionaryTest() { CloneDictModel model = new CloneDictModel(); model.Dicts = new Dictionary <string, string>(); model.Dicts["1"] = "2"; model.Dicts["2"] = "3"; var newModel = CloneOperator.Clone(model); foreach (var item in newModel.Dicts) { Assert.Equal(model.Dicts[item.Key], item.Value); } model.Dicts["1"] = "4"; Assert.NotEqual(model.Dicts, newModel.Dicts); }
public void Clone1DimWithComplex() { var random = new Random(); Member[] arrIns0 = null; // var arrIns1 = new object[] { new Member(), new Member(), new Member() }; var arrIns2 = Mocker.MockArrayMember(notNull: true); var arrIns3 = new Dictionary <int, int>[] { Mocker.MockDict(), Mocker.MockDict() }; var arrIns4 = new List <int>[] { Mocker.MockList(), Mocker.MockList() }; // var arrIns5 = new dynamic[] { }; var arrIns0_Clone = CloneOperator.Clone(arrIns0); // var arrIns1_Clone = CloneOperator.Clone(arrIns1); var arrIns2_Clone = CloneOperator.Clone(arrIns2); var arrIns3_Clone = CloneOperator.Clone(arrIns3); var arrIns4_Clone = CloneOperator.Clone(arrIns4); // var arrIns5_Clone = CloneOperator.Clone(arrIns5); Assert.Null(arrIns0_Clone); Assert.Equal(arrIns0_Clone, arrIns0); // Assert.Equal(arrIns1_Clone, arrIns1); Assert.NotNull(arrIns2_Clone); Assert.NotSame(arrIns2_Clone, arrIns2); Assert.True(arrIns2_Clone.Length == arrIns2.Length); Assert.Equal(arrIns2_Clone, arrIns2, new MemberArrayEqualityComparer()); Assert.NotNull(arrIns3_Clone); Assert.NotSame(arrIns3_Clone, arrIns3); Assert.True(arrIns3_Clone.Length == arrIns3.Length); Assert.Equal(arrIns3_Clone, arrIns3, new DictArrayEqualityComparer()); Assert.NotNull(arrIns4_Clone); Assert.NotSame(arrIns4_Clone, arrIns4); Assert.True(arrIns4_Clone.Length == arrIns4.Length); Assert.Equal(arrIns4_Clone, arrIns4, new ListArrayEqualityComparer()); // Assert.Equal(arrIns5_Clone, arrIns5); }
public void FluentSheetMetadataCloneTest() { var metadata = new FluentSheetMetadata() { Name = "test", FieldMetadatas = new Dictionary <string, FluentFieldMetadata>() { ["ApplicationName"] = new FluentFieldMetadata() { Name = "ApplicationName", Header = new[] { "申请单位名称" }, Required = true }, } }; var cloneMetadata = CloneOperator.Clone(metadata); Assert.NotSame(metadata, cloneMetadata); }
public void PropSubClassArray() { PropCloneSubNodeModel model = new PropCloneSubNodeModel { Node = new PropCloneNormalModel() { Age = 1, Name = "111" } }; var newModel = CloneOperator.Clone(model); Assert.Equal(model.Node.Name, newModel.Node.Name); Assert.Equal(model.Node.Age, newModel.Node.Age); }
public void NotClassArray() { FieldCloneArrayModel model = new FieldCloneArrayModel(); model.Name = new string[10]; for (int i = 0; i < 10; i++) { model.Name[i] = i.ToString(); } var newModel = CloneOperator.Clone(model); for (int i = 0; i < 10; i++) { Assert.Equal(model.Name[i], newModel.Name[i]); } }
public void ClassCloneTest() { var model = new TestModel { B = "B", Model1 = new TestModel1("Model1"), Model2 = new TestModel2 { A = "A", B = 1 } }; var testModel = CloneOperator.Clone(model); Assert.NotSame(model, testModel); Assert.Equal(model.B, testModel.B); Assert.Null(model.Model1); Assert.NotSame(model.Model2, testModel.Model2); Assert.Equal(model.Model2.A, testModel.Model2.A); Assert.Equal(model.Model2.B, testModel.Model2.B); }
public void PropNotClassArray() { PropCloneArrayModel model = new PropCloneArrayModel { Name = new string[10] }; for (int i = 0; i < 10; i++) { model.Name[i] = i.ToString(); } var newModel = CloneOperator.Clone(model); for (int i = 0; i < 10; i++) { Assert.Equal(model.Name[i], newModel.Name[i]); } }
public void CloneSelfTest() { FieldSelfLinkModel model = new FieldSelfLinkModel() { Name = "1", Age = 1 }; model.Next = new FieldSelfLinkModel() { Name = "2", Age = 2 }; var newModel = CloneOperator.Clone(model); Assert.NotEqual(model.Next, newModel.Next); Assert.Equal(model.Next.Name, newModel.Next.Name); }