Skip to content

Instantly share code, notes, and snippets.

@jakesays-old
Created August 14, 2017 17:46
Show Gist options
  • Save jakesays-old/4c5e4e5e73d93359416f59a29f8d73f4 to your computer and use it in GitHub Desktop.
Save jakesays-old/4c5e4e5e73d93359416f59a29f8d73f4 to your computer and use it in GitHub Desktop.
Sample usage of property state tracking
using System;
using System.ComponentModel;
using Std.BasicTypes;
// ReSharper disable ImpureMethodCallOnReadonlyValueField
namespace Money.ViewSurface.ViewObjects
{
public class Fill : INotifyPropertyChanged
{
private readonly TrackedBackingStore<int> _fillId;
private readonly TrackedBackingStore<bool> _active;
private readonly TrackedBackingStore<DateTime> _created;
private readonly TrackedBackingStore<DateTime> _modified;
private readonly TrackedBackingStore<int?> _orderId;
private readonly TrackedBackingStore<string> _side;
private readonly TrackedBackingStore<decimal> _quantity;
private readonly TrackedBackingStore<decimal> _price;
private readonly TrackedBackingStore<DateTime> _transactionTime;
private readonly TrackedBackingStore<string> _orderSystem;
private readonly TrackedBackingStore<string> _orderSystemFillIdentifier;
private readonly TrackedBackingStore<bool> _isExchangeSpreadLegFill;
private readonly TrackedBackingStore<string> _message;
private readonly TrackedBackingStore<string> _creationType;
public PropertyTrackingManager Tracker { get; }
public event PropertyChangedEventHandler PropertyChanged
{
add => Tracker.PropertyChanged += value;
remove => Tracker.PropertyChanged -= value;
}
public Fill()
{
Tracker = new PropertyTrackingManager(_propertyNames, this);
_fillId = new TrackedBackingStore<int>(Tracker, 0, (lhs, rhs) => lhs == rhs);
_active = new TrackedBackingStore<bool>(Tracker, 1, (lhs, rhs) => lhs == rhs);
_created = new TrackedBackingStore<DateTime>(Tracker, 2, (lhs, rhs) => lhs == rhs);
_modified = new TrackedBackingStore<DateTime>(Tracker, 3, (lhs, rhs) => lhs == rhs);
_orderId = new TrackedBackingStore<int?>(Tracker, 4, (lhs, rhs) => lhs == rhs);
_side = new TrackedBackingStore<string>(Tracker, 5, (lhs, rhs) => lhs == rhs);
_quantity = new TrackedBackingStore<decimal>(Tracker, 6, (lhs, rhs) => lhs == rhs);
_price = new TrackedBackingStore<decimal>(Tracker, 7, (lhs, rhs) => lhs == rhs);
_transactionTime = new TrackedBackingStore<DateTime>(Tracker, 8, (lhs, rhs) => lhs == rhs);
_orderSystem = new TrackedBackingStore<string>(Tracker, 9, (lhs, rhs) => lhs == rhs);
_orderSystemFillIdentifier = new TrackedBackingStore<string>(Tracker, 10, (lhs, rhs) => lhs == rhs);
_isExchangeSpreadLegFill = new TrackedBackingStore<bool>(Tracker, 11, (lhs, rhs) => lhs == rhs);
_message = new TrackedBackingStore<string>(Tracker, 12, (lhs, rhs) => lhs == rhs);
_creationType = new TrackedBackingStore<string>(Tracker, 13, (lhs, rhs) => lhs == rhs);
}
public int FillId
{
get => _fillId.Get();
set => _fillId.Set(value);
}
public bool Active
{
get => _active.Get();
set => _active.Set(value);
}
public DateTime Created
{
get => _created.Get();
set => _created.Set(value);
}
public DateTime Modified
{
get => _modified.Get();
set => _modified.Set(value);
}
public int? OrderId
{
get => _orderId.Get();
set => _orderId.Set(value);
}
public string Side
{
get => _side.Get();
set => _side.Set(value);
}
public decimal Quantity
{
get => _quantity.Get();
set => _quantity.Set(value);
}
public decimal Price
{
get => _price.Get();
set => _price.Set(value);
}
public DateTime TransactionTime
{
get => _transactionTime.Get();
set => _transactionTime.Set(value);
}
public string OrderSystem
{
get => _orderSystem.Get();
set => _orderSystem.Set(value);
}
public string OrderSystemFillIdentifier
{
get => _orderSystemFillIdentifier.Get();
set => _orderSystemFillIdentifier.Set(value);
}
public bool IsExchangeSpreadLegFill
{
get => _isExchangeSpreadLegFill.Get();
set => _isExchangeSpreadLegFill.Set(value);
}
public string Message
{
get => _message.Get();
set => _message.Set(value);
}
public string CreationType
{
get => _creationType.Get();
set => _creationType.Set(value);
}
private static readonly string[] _propertyNames =
{
nameof(FillId),
nameof(Active),
nameof(Created),
nameof(Modified),
nameof(OrderId),
nameof(Side),
nameof(Quantity),
nameof(Price),
nameof(TransactionTime),
nameof(OrderSystem),
nameof(OrderSystemFillIdentifier),
nameof(IsExchangeSpreadLegFill),
nameof(Message),
nameof(CreationType)
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment