public void TestUntrustedOut() { Derived d = new Derived(); TypeConfiguration.TrustedTypes = TypeMatch.Type <Base>(); ISerializationService serializer = Container.Resolve <ISerializationService>(); Assert.ThrowsException <TypeMatchException>(() => serializer.Serialize(d)); }
public void ExplicitValueSerialize() { Vector2 vector = new Vector2(10, 40); TypeConfiguration.TrustedTypes = TypeMatch.Type <Vector2>(); ISerializationService serializer = Container.Resolve <ISerializationService>(); string json = serializer.Serialize(vector); Console.WriteLine(json); Vector2 newVector = serializer.Deserialize <Vector2>(json); Assert.AreEqual(vector, newVector); }
/// <summary> /// Creates a new <see cref="CustomSerializer{T}"/>. /// </summary> public CustomSerializer() { SupportedTypes = TypeMatch.Type <T>(); }
public void TestConstructedCollection() { Base a = new Base(); Base b = new Base(); Base c = new Base(); Base d = new Base(); CollectionDerived e = new CollectionDerived() { Child = a, Parents = new HashSet <Base> { a, b, c, d } }; TypeConfiguration.TrustedTypes = TypeMatch.Assembly(typeof(SerializerTests).Assembly).Concat(TypeMatch.Type(typeof(HashSet <>))); ISerializationService serializer = Container.Resolve <ISerializationService>(); string json = serializer.Serialize(e); Console.WriteLine(json); Base newE = serializer.Deserialize <Base>(json); Assert.IsInstanceOfType(newE, typeof(CollectionDerived)); var listE = (CollectionDerived)newE; Assert.IsNotNull(listE.Parents); Assert.AreEqual(4, listE.Parents.Count()); Assert.AreEqual(listE.Child, listE.Parents.ElementAt(0)); }
/// <summary> /// Creates a new <see cref="CustomSerializer{T}"/>. /// </summary> public StringSerializer() { SupportedTypes = TypeMatch.Type <T>(); }