コード例 #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);
        }
コード例 #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);
        }
コード例 #3
0
 public void Initialize()
 {
     _source = new SourceData();
     _intermediateComputed = new DirectComputed(_source);
     _computed = new IndirectComputed(_intermediateComputed);
 }
コード例 #4
0
 public DirectComputed(SourceData source)
 {
     _source   = source;
     _property = new Computed <int>(() => _source.SourceProperty);
 }
コード例 #5
0
 public void Initialize()
 {
     _source = new SourceData();
     _intermediateComputed = new DirectComputed(_source);
     _computed             = new IndirectComputed(_intermediateComputed);
 }
コード例 #6
0
 public DirectComputed(SourceData source)
 {
     _source = source;
     _property = new Computed<int>(() => _source.SourceProperty);
 }
コード例 #7
0
 public void Initialize()
 {
     _source = new SourceData();
     _computed = new DirectComputed(_source);
 }
コード例 #8
0
 public void Initialize()
 {
     _source   = new SourceData();
     _computed = new DirectComputed(_source);
 }