IEnumerable.Cast<T> does not run implicit conversion operators

This commit is contained in:
Eric Harding committed 2017-11-10 17:15:27 -05:00
1 parent 1eee21118f
commit cd5c329bab
7 files changed
+13 -12

No files matched your search

@@ -128,6 +128,7 @@ namespace System.Collections.ObjectModel
public static class ObservableCollectionExtensions
{
public static int RemoveAll<T>(this ObservableCollection<T> collection, Func<T, bool> match) {
if (collection == null) return 0;
// In terms of allocations we could do this more efficiently by copying items from the end of the
// collection in (see https://referencesource.microsoft.com/#q=RemoveAll) but that would allow
// transient duplication in the list which could be observed from the outside
@@ -68,7 +68,7 @@ namespace mbts.spark
if (_securities != null && _securities.TryGetValue((uint)header.version, out SecurityMD md)) return create_ladder_window(md);
else break;
case MarketViewVM.SAVE_NAME:
if (try_deserialize(load_stream, out MarketViewVM.StartupData data)) return create_market_view(data.securities.Select(deserialize<Security>).Cast<SecurityImmutable>().ToList(), data.sorting_criteria);
if (try_deserialize(load_stream, out MarketViewVM.StartupData data)) return create_market_view(data.securities.Select(x => (SecurityImmutable)deserialize<Security>(x)).ToList(), data.sorting_criteria);
else break;
}
}
@@ -13,7 +13,7 @@ namespace mbts.spark
internal class TimeAndSalesWindow : IShellWindow
{
public TimeAndSalesWindow(IShellModule owner, IBus bus, IReadOnlyCollection<SecurityImmutable> securities) : this (owner, bus, securities, null) { }
public TimeAndSalesWindow(IShellModule owner, IBus bus, TimeAndSalesVM.StartupData startup_data) : this(owner, bus, startup_data.securities.Select(deserialize<Security>).Cast<SecurityImmutable>().ToList(), startup_data.sorting_criteria) { }
public TimeAndSalesWindow(IShellModule owner, IBus bus, TimeAndSalesVM.StartupData startup_data) : this(owner, bus, startup_data.securities.Select(x => (SecurityImmutable)deserialize<Security>(x)).ToList(), startup_data.sorting_criteria) { }
private TimeAndSalesWindow(IShellModule owner, IBus bus, IReadOnlyCollection<SecurityImmutable> securities, IReadOnlyCollection<SortingCriteria> sorting_criteria) {
_bus = bus;
@@ -68,7 +68,7 @@ namespace mbts.spark
return ShellWindow.create(this, "Order Book", view, vm.get_state);
}
private IShellWindow create_fills_window(FillsVM.StartupData startup_data) { return create_fills_window(startup_data.securities?.Select(deserialize<Security>).Cast<SecurityImmutable>().ToList(), startup_data.sorting_criteria); }
private IShellWindow create_fills_window(FillsVM.StartupData startup_data) { return create_fills_window(startup_data.securities?.Select(x => (SecurityImmutable)deserialize<Security>(x)).ToList(), startup_data.sorting_criteria); }
private IShellWindow create_fills_window(IReadOnlyCollection<SecurityImmutable> securities) { return create_fills_window(securities, null); }
private IShellWindow create_fills_window(IReadOnlyCollection<SecurityImmutable> securities, IReadOnlyCollection<SortingCriteria> sorting_criteria) {
var vm = new FillsVM(_bus, new OrdersModel(_bus), securities, sorting_criteria);
@@ -19,7 +19,7 @@ namespace mbts.ui.spark
#region Value
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), typeof(PriceEntryControl),new FrameworkPropertyMetadata(double.NaN, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, null, CoerceValue));
private static object CoerceValue(DependencyObject d, object baseValue) { return TickUtils.get_regional_ticks((ContractSpecification)d.GetValue(ContractSpecProperty)).round((double)baseValue); }
private static object CoerceValue(DependencyObject d, object baseValue) { return TickUtils.get_regional_ticks((ContractSpecificationImmutable)d.GetValue(ContractSpecProperty)).round((double)baseValue); }
public double Value { get => (double)GetValue(ValueProperty); set => SetValue(ValueProperty, value); }
#endregion
@@ -36,9 +36,9 @@ namespace mbts.ui.spark
#endregion
#region ContractSpec
public static readonly DependencyProperty ContractSpecProperty = DependencyProperty.Register("ContractSpec", typeof(ContractSpecification), typeof(PriceEntryControl), new PropertyMetadata(TickUtils.DefaultSpec, OnContractSpecChanged));
public static readonly DependencyProperty ContractSpecProperty = DependencyProperty.Register("ContractSpec", typeof(ContractSpecificationImmutable), typeof(PriceEntryControl), new PropertyMetadata(TickUtils.DefaultSpec, OnContractSpecChanged));
private static void OnContractSpecChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ((PriceEntryControl)d)._update_text_binding(); }
public ContractSpecificationImmutable ContractSpec { get => GetValue(ContractSpecProperty) as ContractSpecification; set => SetValue(ContractSpecProperty, value); }
public ContractSpecificationImmutable? ContractSpec { get => GetValue(ContractSpecProperty) as ContractSpecificationImmutable?; set => SetValue(ContractSpecProperty, value); }
#endregion
public PriceEntryControl() {
@@ -48,8 +48,8 @@ namespace mbts.ui.spark
private TextBox _text;
private void _tick_up() { SetCurrentValue(ValueProperty, ContractSpec.tickup(Value)); }
private void _tick_down() { SetCurrentValue(ValueProperty, ContractSpec.tickdown(Value)); }
private void _tick_up() { SetCurrentValue(ValueProperty, ContractSpec.HasValue ? ContractSpec.Value.tickup(Value) : Value); }
private void _tick_down() { SetCurrentValue(ValueProperty, ContractSpec.HasValue ? ContractSpec.Value.tickdown(Value) : Value); }
private void _update_text_binding() {
if (_text != null) {
@@ -25,16 +25,16 @@ namespace mbts.ui.spark.converters
internal class TickDisplayTwoWayConverter : IValueConverter
{
public bool HideNaN { get; set; }
public ContractSpecificationImmutable ContractSpec { get; set; } = new ContractSpecification { CashPerPoint = 1.0, LowTick = 0.01, HighTick = 0.01, PriceBreak = double.MaxValue, PriceMultiplier = 1.0 };
public ContractSpecificationImmutable? ContractSpec { get; set; } = new ContractSpecification { CashPerPoint = 1.0, LowTick = 0.01, HighTick = 0.01, PriceBreak = double.MaxValue, PriceMultiplier = 1.0 };
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
var price = (double)value;
if (HideNaN && double.IsNaN(price)) return string.Empty;
return ContractSpec.format(price);
return ContractSpec.Value.format(price);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
return ContractSpec.parse(value as string);
return ContractSpec.Value.parse(value as string);
}
}
}
@@ -65,7 +65,7 @@ namespace {{package}} {
{{else}}
{{#if type.islist}}
// Can remove the cast if immutable==cstype
public IEnumerable<{{type.immutable}}> {{Name}} => _impl.{{Name}}.Cast<{{type.immutable}}>();
public IEnumerable<{{type.immutable}}> {{Name}} => _impl.{{Name}}.Select(t => ({{type.immutable}})t);
{{else}}
public {{type.immutable}} {{Name}} => ({{type.immutable}})_impl.{{Name}};
{{/if}}