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); }
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); }
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); } }
public EventValueChange(PublishedValue <T> value) { this.value = value; }
public IntToStringBinding(PublishedValue <int> fromValue, PublishedValue <string> toValue) : base(fromValue, toValue) { }
public StringBinding(PublishedValue <string> fromValue, PublishedValue <string> toValue) : base(fromValue, toValue) { }