Exemplo n.º 1
0
        public void DirectComputedObjectCanBeGarbageCollected()
        {
            GC.Collect();
            SourceData observable = new SourceData();
            DirectComputed computed = new DirectComputed(observable);
            observable.SourceProperty = 42;
            Assert.AreEqual(42, computed.ComputedProperty);
            WeakReference weakComputed = new WeakReference(computed);

            GC.Collect();
            Assert.IsTrue(weakComputed.IsAlive, "Since we hold a strong reference to the dependent, the object should still be alive.");
            // This assertion here to make sure the dependent is not optimized away.
            Assert.AreEqual(42, computed.ComputedProperty);

            computed = null;
            GC.Collect();
            Assert.IsFalse(weakComputed.IsAlive, "Since we released the strong reference to the dependent, the object should not be alive.");

            // Make sure we can still modify the observable.
            observable.SourceProperty = 32;
            Assert.AreEqual(32, observable.SourceProperty);
        }
Exemplo n.º 2
0
        public void DirectComputedObjectCanBeGarbageCollected()
        {
            GC.Collect();
            SourceData     observable = new SourceData();
            DirectComputed computed   = new DirectComputed(observable);

            observable.SourceProperty = 42;
            Assert.AreEqual(42, computed.ComputedProperty);
            WeakReference weakComputed = new WeakReference(computed);

            GC.Collect();
            Assert.IsTrue(weakComputed.IsAlive, "Since we hold a strong reference to the dependent, the object should still be alive.");
            // This assertion here to make sure the dependent is not optimized away.
            Assert.AreEqual(42, computed.ComputedProperty);

            computed = null;
            GC.Collect();
            Assert.IsFalse(weakComputed.IsAlive, "Since we released the strong reference to the dependent, the object should not be alive.");

            // Make sure we can still modify the observable.
            observable.SourceProperty = 32;
            Assert.AreEqual(32, observable.SourceProperty);
        }
 public void Initialize()
 {
     _source = new SourceData();
     _intermediateComputed = new DirectComputed(_source);
     _computed = new IndirectComputed(_intermediateComputed);
 }
Exemplo n.º 4
0
 public DirectComputed(SourceData source)
 {
     _source   = source;
     _property = new Computed <int>(() => _source.SourceProperty);
 }
Exemplo n.º 5
0
 public void Initialize()
 {
     _source = new SourceData();
     _intermediateComputed = new DirectComputed(_source);
     _computed             = new IndirectComputed(_intermediateComputed);
 }
Exemplo n.º 6
0
 public DirectComputed(SourceData source)
 {
     _source = source;
     _property = new Computed<int>(() => _source.SourceProperty);
 }
 public void Initialize()
 {
     _source = new SourceData();
     _computed = new DirectComputed(_source);
 }
 public void Initialize()
 {
     _source   = new SourceData();
     _computed = new DirectComputed(_source);
 }