public void TestCollectionsReflective() { ICollection<PortableTypeConfiguration> typeCfgs = new List<PortableTypeConfiguration>(); typeCfgs.Add(new PortableTypeConfiguration(typeof(CollectionsType))); typeCfgs.Add(new PortableTypeConfiguration(typeof(InnerObjectType))); PortableConfiguration cfg = new PortableConfiguration(); cfg.TypeConfigurations = typeCfgs; PortableMarshaller marsh = new PortableMarshaller(cfg); CollectionsType obj = new CollectionsType(); ArrayList list = new ArrayList(); list.Add(true); list.Add((byte)1); list.Add((short)2); list.Add('a'); list.Add(3); list.Add((long)4); list.Add((float)5); list.Add((double)6); list.Add("string"); list.Add(Guid.NewGuid()); InnerObjectType innerObj = new InnerObjectType(); innerObj.PInt1 = 1; innerObj.PInt2 = 2; list.Add(innerObj); obj.Col1 = list; byte[] bytes = marsh.Marshal(obj); IPortableObject portObj = marsh.Unmarshal<IPortableObject>(bytes, PortableMode.ForcePortable); Assert.AreEqual(obj.GetHashCode(), portObj.GetHashCode()); CollectionsType newObj = portObj.Deserialize<CollectionsType>(); Assert.AreEqual(obj, newObj); obj.Col1 = null; Assert.AreEqual(obj, marsh.Unmarshal<CollectionsType>(marsh.Marshal(obj))); obj.Col1 = list; obj.Col2 = list; Assert.AreEqual(obj, marsh.Unmarshal<CollectionsType>(marsh.Marshal(obj))); obj.Col2 = new TestList(); Assert.AreEqual(obj, marsh.Unmarshal<CollectionsType>(marsh.Marshal(obj))); }
private static void CheckObject(PortableMarshaller marsh, OuterObjectType outObj, InnerObjectType inObj) { inObj.PInt1 = 1; inObj.PInt2 = 2; outObj.InObj = inObj; byte[] bytes = marsh.Marshal(outObj); IPortableObject portOutObj = marsh.Unmarshal<IPortableObject>(bytes, PortableMode.ForcePortable); Assert.AreEqual(outObj.GetHashCode(), portOutObj.GetHashCode()); OuterObjectType newOutObj = portOutObj.Deserialize<OuterObjectType>(); Assert.AreEqual(outObj, newOutObj); }