Esempio n. 1
0
    public void TestSerializableEventsActionSucceeds()
    {
      var root = new OverrideSerializationRoot();
      var nonSerClass = new NonSerializedClass();

      Action<object, PropertyChangedEventArgs> h = (sender, eventArgs) => { nonSerClass.Do(); };
      var method = typeof (Action<object, PropertyChangedEventArgs>).GetMethod("Invoke");
      var delgate = (PropertyChangedEventHandler)(object)method.CreateDelegate(typeof (PropertyChangedEventHandler), h);
      root.PropertyChanged += delgate;

      Action<object, PropertyChangingEventArgs> h1 = (sender, eventArgs) => { nonSerClass.Do(); };
      var method1 = typeof(Action<object, PropertyChangingEventArgs>).GetMethod("Invoke");
      var delgate1 = (PropertyChangingEventHandler)(object)method1.CreateDelegate(typeof(PropertyChangingEventHandler), h1);
      root.PropertyChanging += delgate1;

      var b = new BinaryFormatterWrapper();
      b.Serialize(new MemoryStream(), root);
    }
Esempio n. 2
0
 public void TestSerializableEventsActionFails()
 {
   var root = new SerializationRoot();
   var nonSerClass = new NonSerializedClass();
   Action<object, PropertyChangedEventArgs> h = (sender, eventArgs) => { nonSerClass.Do(); };
   var method = typeof (Action<object, PropertyChangedEventArgs>).GetMethod("Invoke");
   var delgate = (PropertyChangedEventHandler)(object)method.CreateDelegate(typeof (PropertyChangedEventHandler), h);
   root.PropertyChanged += delgate;
   var b = new BinaryFormatterWrapper();
   try
   {
     b.Serialize(new MemoryStream(), root);
     Assert.Fail("Serialization should have thrown an exception");
   }
   catch (System.Runtime.Serialization.SerializationException)
   {
     // serialization failed as expected
   }
 }