Example #1
0
        public Binding(PublishedValue <FromType> fromValue, PublishedValue <ToType> toValue)
        {
            if (null == fromValue || null == toValue)
            {
                return;
            }

            toValue.Value = Transform(fromValue.Value);

            // Avoid strong reference captures (binding doesn't claim ownership of objects it binds to)
            this.fromValue = new WeakReference <PublishedValue <FromType> >(fromValue);
            fromValue.AddListener(this);

            this.toValue = new WeakReference <PublishedValue <ToType> >(toValue);
        }
Example #2
0
        public void TestBinding()
        {
            var intValue    = new PublishedValue <int>(10);
            var stringValue = new PublishedValue <string>("hello");

            Assert.AreEqual("hello", stringValue.Value);
            Assert.AreEqual(10, intValue.Value);

            var binding = new IntToStringBinding(intValue, stringValue);

            Assert.AreEqual("10", stringValue.Value);
            Assert.AreEqual(10, intValue.Value);

            intValue.Value = 5;
            Assert.AreEqual("5", stringValue.Value);
        }
Example #3
0
        public void Deposit(Price price)
        {
            if (price.amount < 0)
            {
                return;
            }

            if (accounts.TryGetValue(price.currency, out PublishedValue <int> amount))
            {
                amount.Value = amount.Value + price.amount;
            }
            else
            {
                var value = new PublishedValue <int>();
                value.Value = price.amount;
                accounts.Add(price.currency, value);
            }
        }
Example #4
0
 public EventValueChange(PublishedValue <T> value)
 {
     this.value = value;
 }
Example #5
0
 public IntToStringBinding(PublishedValue <int> fromValue, PublishedValue <string> toValue) : base(fromValue, toValue)
 {
 }
Example #6
0
 public StringBinding(PublishedValue <string> fromValue, PublishedValue <string> toValue) : base(fromValue, toValue)
 {
 }