public void Serialization1() { MainObject mainObj = new MainObject(); MainObjectRepoSerMgr mainObjSerMgr = MainObjectRepoSerMgr.Singleton; RepositorySerializationContext serCtx = new RepositorySerializationContext(); RepositorySerializationContext serCtx2 = new RepositorySerializationContext(); String serialization = null; TextWriter tw = new StringWriter(); if (typeof(IMainObject).GetTypeGuid().ToString() == "e94473ee-f53f-4b7b-95d6-36d78d327e86") { System.Diagnostics.Debug.WriteLine("Guid verificato"); } mainObj.DateTimeField = DateTime.Now; mainObj.Field3 = new SubObject(); mainObj.Field1 = "String Field \", \"aaa\" : \"bbb\", Insidioso"; mainObj.Field2 = "Mario"; mainObj.Field3.SubObjField1 = "Sub 1"; mainObj.Field3.SubObjField2 = "Sub 2"; mainObj.Field4 = true; mainObj.Field8 = -1234567.890; serCtx.SerializeMetadata = true; mainObjSerMgr.Serialize(tw, mainObj, serCtx); tw.Flush(); tw.Close(); serialization = tw.ToString(); using (StringReader sr1 = new StringReader(serialization)) { IMainObject deserResult = mainObjSerMgr.Deserialize(sr1, serCtx2); IMainObjectSerializationContract ppp = deserResult as IMainObjectSerializationContract; ppp.Field1 = "Primo"; ppp.Field2 = "Coccodrillo"; ppp.Field4 = false; ppp.Field8 = 987.654; IValueDomAlignable <IValueUnit, IValueUnit> vDomAligner = deserResult as IValueDomAlignable <IValueUnit, IValueUnit>; if (vDomAligner != null) { vDomAligner.Align(); if (vDomAligner.GetContext(ref serCtx2)) { serCtx2.SerializeData = true; serCtx2.SerializeMetadata = true; tw = new StringWriter(); mainObjSerMgr.Serialize(tw, vDomAligner.Data, serCtx2); serialization = tw.ToString(); } } } MainObjectFactory mainFact = MainObjectFactory.Singleton; mainFact.InitDto.DateTimeField = DateTime.Now; mainFact.InitDto.Field1 = "Test"; mainFact.InitDto.Field2 = "Mario"; mainFact.InitDto.Field4 = false; mainFact.InitDto.Field8 = 9876.54; mainFact.InitDto.Field3.SubObjField1 = "Init Sub 1"; mainFact.InitDto.Field3.SubObjField2 = "Init Sub 2"; IMainObject k = mainFact.GetByDto(); } // End of Serialization1 ()
public void Serialization1() { IMainObject mainObj = MainObjectFactory.Singleton.GetNew(); MainObjectRepoSerMgr mainObjSerMgr = MainObjectRepoSerMgr.Singleton; RepositorySerializationContext serCtx = new RepositorySerializationContext(); RepositorySerializationContext serCtx2 = new RepositorySerializationContext(); ISubObject subObject = null; if (typeof(IMainObject).GetTypeGuid().ToString() == "e94473ee-f53f-4b7b-95d6-36d78d327e86") { System.Diagnostics.Debug.WriteLine("Guid verificato"); } mainObj.DateTimeField = DateTime.Now; mainObj.Field3 = SubObjectFactory.Singleton.GetNew(); mainObj.Field1 = "String Field \", \"aaa\" : \"bbb\", Insidioso"; mainObj.Field2 = "Mario"; mainObj.Field3.SubObjField1 = "Sub 1"; mainObj.Field3.SubObjField2 = "Sub 2"; mainObj.Field4 = true; mainObj.Field5 = new List <ISubObject> (); mainObj.Field6 = new List <Object> (); mainObj.Field6Bis = (IList)mainObj.Field6; mainObj.Field7 = new Dictionary <String, ISubObject> (); mainObj.Field8 = -1234567.890; mainObj.BooleanArray = new Boolean [] { true, false, true }; mainObj.DateTimeArray = new DateTime [] { DateTime.Now.AddDays(-1), DateTime.Now, DateTime.Now.AddDays(1) }; mainObj.Int32Array = new Int32 [] { 123, 456, 789 }; mainObj.MixedArray = new Object [] { 123, true, DateTime.Now }; mainObj.SubObjectArray = new ISubObject [2]; subObject = SubObjectFactory.Singleton.GetNew(); subObject.SubObjField1 = "Collection Item 1 Field 1"; subObject.SubObjField2 = "Collection Item 1 Field 2"; mainObj.Field5.Add(subObject); mainObj.Field6.Add(subObject); mainObj.SubObjectArray [0] = subObject; subObject = SubObjectFactory.Singleton.GetNew(); subObject.SubObjField1 = "Collection Item 2 Field 1"; subObject.SubObjField2 = "Collection Item 2 Field 2"; mainObj.Field5.Add(subObject); mainObj.SubObjectArray [1] = subObject; mainObj.Field6.Add("Ciccio Pasticcio"); mainObj.Field6.Add(subObject); mainObj.Field7.Add("Dictionary Test", subObject); //dynamic test = MainObjectFactory.Singleton.ExportToJson ( mainObj ); TextWriter tw = new StringWriter(); serCtx.SerializeMetadata = true; mainObjSerMgr.Serialize(tw, mainObj, serCtx); tw.Flush(); tw.Close(); String serialization = tw.ToString(); using (StringReader sr1 = new StringReader(serialization)) { IMainObject deserResult = mainObjSerMgr.Deserialize(sr1, serCtx2); } } // End of Serialization1 ()