rename ObjectHelper -> ConvertUtils
This commit is contained in:
1 parent
ba07041c26
commit
bc367b9f56
25 files changed
+45
-48
No files matched your search
@@ -58,7 +58,7 @@ namespace mbts.spark {
|
||||
var update_securities_cmd = SparkCommands.change_securities_callback(_window_type_display_name);
|
||||
_commands = new List<SparkCommand> {
|
||||
SparkCommands.ShowLadders.complete(_vm.selected_security_mds_observable(), smds => smds.Count > 0),
|
||||
SparkCommands.ShowOrderTicketFromSecurity.complete(_vm.current_security_md, md => md.HasValue, ObjectHelper.ValueOrDefault),
|
||||
SparkCommands.ShowOrderTicketFromSecurity.complete(_vm.current_security_md, md => md.HasValue, ConvertUtils.ValueOrDefault),
|
||||
SparkCommands.ShowFills.complete(_vm.selected_securities_observable(), _ => true,
|
||||
secs => new FillsWindowFactory.StartupData(new FillsWindowFactory.FilterStates {
|
||||
security = secs.Count > 0 ? new SecurityCriteria(secs) : _state.security_criteria
|
||||
|
||||
@@ -62,8 +62,8 @@ namespace mbts.spark {
|
||||
var current_smd_source = connectable_builder.create(vm => vm.current_security_md_observable(_bus)).OnDispatcher();
|
||||
var selected_secs_source = connectable_builder.create(vm => vm.selected_securities_observable()).OnDispatcher();
|
||||
_commands = new SparkCommand[] {
|
||||
SparkCommands.ShowLadder.complete(current_smd_source, md => md.HasValue, ObjectHelper.ValueOrDefault),
|
||||
SparkCommands.ShowOrderTicketFromSecurity.complete(current_smd_source, md => md.HasValue, ObjectHelper.ValueOrDefault),
|
||||
SparkCommands.ShowLadder.complete(current_smd_source, md => md.HasValue, ConvertUtils.ValueOrDefault),
|
||||
SparkCommands.ShowOrderTicketFromSecurity.complete(current_smd_source, md => md.HasValue, ConvertUtils.ValueOrDefault),
|
||||
SparkCommands.ShowFills.complete(selected_secs_source, always_true, get_fills_startup_data),
|
||||
SparkCommands.ShowMarketView.complete(selected_secs_source, always_true, secs => secs.Count > 0 ? new SecurityCriteria(secs) : _state.security_criteria),
|
||||
SparkCommands.change_securities_command(() => (update_securities_cmd, _state.security_criteria)),
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace mbts.spark {
|
||||
current_row_connectable_builder.create(observe_row_strategy),
|
||||
rs => rs.HasValue, select_row_strategy_tuple
|
||||
), SparkCommands.ShowLadder.complete(
|
||||
vm_connectable_builder.create(vm => vm.current_security_md), md => md.HasValue, ObjectHelper.ValueOrDefault
|
||||
vm_connectable_builder.create(vm => vm.current_security_md), md => md.HasValue, ConvertUtils.ValueOrDefault
|
||||
), SparkCommands.ShowOrders.complete(() => new OrderBookWindowFactory.OrderBookStartupData {
|
||||
filters = new OrderBookWindowFactory.FilterStates {
|
||||
security_criteria = new SecurityCriteria(_vm.value.row_vms.Select(r => r.security))
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace mbts.ui {
|
||||
public bool CanExecute(object parameter) {
|
||||
if (!allow_concurrent_executions && _n_executing > 0)
|
||||
return false;
|
||||
else return _can_execute(ObjectHelper.try_convert<T>(parameter));
|
||||
else return _can_execute(ConvertUtils.try_convert<T>(parameter));
|
||||
}
|
||||
|
||||
public async Task Execute(object parameter) {
|
||||
@@ -51,7 +51,7 @@ namespace mbts.ui {
|
||||
if (!allow_concurrent_executions)
|
||||
RaiseCanExecuteChanged();
|
||||
}
|
||||
await _execute(ObjectHelper.try_convert<T>(parameter));
|
||||
await _execute(ConvertUtils.try_convert<T>(parameter));
|
||||
if (--_n_executing == 0) {
|
||||
_raise_is_executing_changed();
|
||||
if (!allow_concurrent_executions)
|
||||
|
||||
@@ -27,13 +27,13 @@ namespace mbts.ui
|
||||
if (_can_execute == null)
|
||||
return true;
|
||||
else
|
||||
return _can_execute(ObjectHelper.try_convert<T>(parameter));
|
||||
return _can_execute(ConvertUtils.try_convert<T>(parameter));
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public void Execute(object parameter) =>
|
||||
_execute(ObjectHelper.try_convert<T>(parameter));
|
||||
_execute(ConvertUtils.try_convert<T>(parameter));
|
||||
}
|
||||
|
||||
public class DelegateCommand : DelegateCommand<object> {
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace mbts.ui {
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public bool CanExecute(object parameter) => _can_execute;
|
||||
public void Execute(object parameter) => _execute(ObjectHelper.try_convert<T>(parameter));
|
||||
public void Execute(object parameter) => _execute(ConvertUtils.try_convert<T>(parameter));
|
||||
|
||||
public void OnCompleted() { }
|
||||
public void OnError(Exception error) { }
|
||||
|
||||
@@ -364,7 +364,7 @@ namespace System.Collections.Generic {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses <see cref="ObjectHelper.try_convert{TResult}(object)"/> to convert the elements of an <see cref="IEnumerable"/> to the specified type.
|
||||
/// Uses <see cref="ConvertUtils.try_convert{TResult}(object)"/> to convert the elements of an <see cref="IEnumerable"/> to the specified type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">The type to convert the elements of source to.</typeparam>
|
||||
/// <param name="source">The <see cref="IEnumerable"/> that contains the elements to be cast to type <typeparamref name="TResult"/></param>
|
||||
@@ -373,7 +373,7 @@ namespace System.Collections.Generic {
|
||||
public static IEnumerable<TResult> convert<TResult>(this IEnumerable source) {
|
||||
ExceptionAssert.Argument.NotNull(source, nameof(source));
|
||||
foreach (object obj in source)
|
||||
yield return ObjectHelper.try_convert<TResult>(obj);
|
||||
yield return ConvertUtils.try_convert<TResult>(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -348,7 +348,7 @@ namespace mbts.ui.controls {
|
||||
|
||||
class BadgeTextLinesConverter : IMultiValueConverter {
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (ObjectHelper.try_convert_args(values, out Side side, out uint quantity, out uint filled, out mbts.spark.LadderSettings.BadgeStyle style))
|
||||
if (ConvertUtils.try_convert_args(values, out Side side, out uint quantity, out uint filled, out mbts.spark.LadderSettings.BadgeStyle style))
|
||||
return BadgeRender.format(side, quantity, filled, style);
|
||||
else return new string[0];
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ namespace mbts.ui.controls.color_picker {
|
||||
public DataTemplate EditableTemplate { get; set; }
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (ObjectHelper.try_convert_args(values, out ColorPaletteVM vm, out bool is_selected)) {
|
||||
if (ConvertUtils.try_convert_args(values, out ColorPaletteVM vm, out bool is_selected)) {
|
||||
if (vm.can_user_edit && is_selected)
|
||||
return EditableTemplate;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace mbts.ui.controls.color_picker {
|
||||
|
||||
class NamedColorItemToolTipConverter : IMultiValueConverter {
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) =>
|
||||
ObjectHelper.try_convert_args(values, out string name, out bool can_user_edit) ?
|
||||
ConvertUtils.try_convert_args(values, out string name, out bool can_user_edit) ?
|
||||
$"{name} (Alt + Click for info{(can_user_edit ? ", Ctrl + Click to assign" : string.Empty)})" :
|
||||
string.Empty;
|
||||
|
||||
|
||||
@@ -109,6 +109,6 @@ namespace mbts.spark.filters {
|
||||
protected virtual void _validate() { }
|
||||
|
||||
bool IDataGridColumnFilter.filter(object row) =>
|
||||
filter(ObjectHelper.try_convert<TRow>(row));
|
||||
filter(ConvertUtils.try_convert<TRow>(row));
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,6 @@ namespace mbts.spark.filters {
|
||||
|
||||
|
||||
bool IDataGridColumnFilter.filter(object row) =>
|
||||
filter(ObjectHelper.try_convert<TRow>(row));
|
||||
filter(ConvertUtils.try_convert<TRow>(row));
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ namespace mbts.ui.controls
|
||||
protected DataGridExRow() { }
|
||||
|
||||
public abstract object get_cell(TColKey col_key);
|
||||
public object get_cell(object col_key) { return get_cell(ObjectHelper.try_convert<TColKey>(col_key)); }
|
||||
public object get_cell(object col_key) { return get_cell(ConvertUtils.try_convert<TColKey>(col_key)); }
|
||||
|
||||
|
||||
}
|
||||
@@ -60,6 +60,6 @@ namespace mbts.ui.controls
|
||||
public abstract class DataGridExCell<TData> : ViewModelBase, IDataGridExCell<TData>, IDataGridExCell
|
||||
{
|
||||
public abstract void update(TData data);
|
||||
public void update(object data) { update(ObjectHelper.try_convert<TData>(data)); }
|
||||
public void update(object data) { update(ConvertUtils.try_convert<TData>(data)); }
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace mbts.ui.controls {
|
||||
|
||||
class FontFamilySupportsWeightConverter : IMultiValueConverter {
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (ObjectHelper.try_convert_args(values, out FontFamily ff, out FontWeight fw))
|
||||
if (ConvertUtils.try_convert_args(values, out FontFamily ff, out FontWeight fw))
|
||||
return TextUtils.available_weights(ff).Contains(fw);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ namespace mbts.ui.converters {
|
||||
private readonly Func<TIn, TOut> _convert;
|
||||
private readonly Func<TOut, TIn> _convert_back;
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return _convert(ObjectHelper.try_convert<TIn>(value)); }
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return _convert_back(ObjectHelper.try_convert<TOut>(value)); }
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return _convert(ConvertUtils.try_convert<TIn>(value)); }
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return _convert_back(ConvertUtils.try_convert<TOut>(value)); }
|
||||
}
|
||||
|
||||
public class AnonymousMultiValueConverter<TIn1, TIn2, TOut> : IMultiValueConverter {
|
||||
@@ -49,7 +49,7 @@ namespace mbts.ui.converters {
|
||||
public TOut ErrorValue { get; set; }
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) =>
|
||||
ObjectHelper.try_convert_args(values, out TIn1 a, out TIn2 b) ? _convert(a, b) : ErrorValue;
|
||||
ConvertUtils.try_convert_args(values, out TIn1 a, out TIn2 b) ? _convert(a, b) : ErrorValue;
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||
}
|
||||
@@ -62,7 +62,7 @@ namespace mbts.ui.converters {
|
||||
public TOut ErrorValue { get; set; }
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) =>
|
||||
ObjectHelper.try_convert_args(values, out TIn1 a, out TIn2 b, out TIn3 c) ? _convert(a, b, c) : ErrorValue;
|
||||
ConvertUtils.try_convert_args(values, out TIn1 a, out TIn2 b, out TIn3 c) ? _convert(a, b, c) : ErrorValue;
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace mbts.ui.converters
|
||||
}
|
||||
|
||||
public class DynamicValueEquals<T> : DynamicValueEquals {
|
||||
protected override bool ValuesEqual(object x, object y) { return ObjectHelper.try_convert(x, out T tx) && ObjectHelper.try_convert(y, out T ty) && ValuesEqual(tx, ty); }
|
||||
protected override bool ValuesEqual(object x, object y) { return ConvertUtils.try_convert(x, out T tx) && ConvertUtils.try_convert(y, out T ty) && ValuesEqual(tx, ty); }
|
||||
protected virtual bool ValuesEqual(T x, T y) { return CompareUtils.NullCheckEquals(x, y); }
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace mbts.ui.converters
|
||||
}
|
||||
|
||||
public class StaticValueEqualsConverter<T> : StaticValueEqualsConverter {
|
||||
protected override bool ValueEquals(object value) { return ObjectHelper.try_convert(value, out T result) && ValueEquals(result); }
|
||||
protected override bool ValueEquals(object value) { return ConvertUtils.try_convert(value, out T result) && ValueEquals(result); }
|
||||
protected virtual bool ValueEquals(T value) { return base.ValueEquals(value); }
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace mbts.ui
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public bool CanExecute(object parameter) {
|
||||
return !_is_executing && (_can_execute == null || _can_execute(ObjectHelper.try_convert<T>(parameter)));
|
||||
return !_is_executing && (_can_execute == null || _can_execute(ConvertUtils.try_convert<T>(parameter)));
|
||||
}
|
||||
|
||||
public void RaiseCanExecuteChanged() {
|
||||
@@ -45,7 +45,7 @@ namespace mbts.ui
|
||||
_is_executing = true;
|
||||
RaiseCanExecuteChanged();
|
||||
try {
|
||||
var w = await _factory(ObjectHelper.try_convert<T>(parameter));
|
||||
var w = await _factory(ConvertUtils.try_convert<T>(parameter));
|
||||
if (w != null) {
|
||||
if (_off_x.HasValue && _off_y.HasValue)
|
||||
w.move_to_mouse(_off_x.Value, _off_x.Value);
|
||||
|
||||
@@ -28,12 +28,12 @@ namespace mbts.ui
|
||||
private IDisposable _dialog;
|
||||
public Predicate<T> can_execute { get; set; }
|
||||
|
||||
public bool CanExecute(object parameter) { return can_execute == null ? true : can_execute(ObjectHelper.try_convert<T>(parameter)); }
|
||||
public bool CanExecute(object parameter) { return can_execute == null ? true : can_execute(ConvertUtils.try_convert<T>(parameter)); }
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public void Execute(object parameter) {
|
||||
Disposable.dispose(ref _dialog);
|
||||
Window w = _factory(ObjectHelper.try_convert<T>(parameter));
|
||||
Window w = _factory(ConvertUtils.try_convert<T>(parameter));
|
||||
if (w != null) {
|
||||
if (_try_dispose_vm_on_close) {
|
||||
w.Closed += (s, e) => {
|
||||
|
||||
@@ -101,10 +101,10 @@ namespace mbts.ui {
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public bool CanExecute(object parameter) => _can_execute(ObjectHelper.try_convert<TParam>(parameter));
|
||||
public bool CanExecute(object parameter) => _can_execute(ConvertUtils.try_convert<TParam>(parameter));
|
||||
public void Execute(object parameter) {
|
||||
_safe_close_dialog();
|
||||
TParam tparam = ObjectHelper.try_convert<TParam>(parameter);
|
||||
TParam tparam = ConvertUtils.try_convert<TParam>(parameter);
|
||||
_dialog = _dialog_factory(tparam);
|
||||
if (_dialog.ShowDialog() == DialogResult.OK)
|
||||
_commit(tparam, _dialog.FileName);
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace mbts.ui {
|
||||
|
||||
public static T get_template_child<T>(this Control control, string name) {
|
||||
object obj = get_template_child(control, name);
|
||||
return ObjectHelper.try_convert<T>(obj);
|
||||
return ConvertUtils.try_convert<T>(obj);
|
||||
}
|
||||
|
||||
public static bool try_get_template_child(this Control control, string name, out object result) {
|
||||
@@ -40,7 +40,7 @@ namespace mbts.ui {
|
||||
|
||||
public static bool try_get_template_child<T>(this Control control, string name, out T result) {
|
||||
if (try_get_template_child(control, name, out object obj))
|
||||
return ObjectHelper.try_convert(obj, out result);
|
||||
return ConvertUtils.try_convert(obj, out result);
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -853,11 +853,11 @@ namespace mbts.spark {
|
||||
LadderSettings _settings => _owner._settings;
|
||||
|
||||
public void refresh() {
|
||||
bid_dirty = ObjectHelper.update_value_type(ref _bid, _settings.bid_break_line.show ? _owner._get_bid_market_break() : double.NaN);
|
||||
ask_dirty = ObjectHelper.update_value_type(ref _ask, _settings.ask_break_line.show ? _owner._get_ask_market_break() : double.NaN);
|
||||
mid_dirty = ObjectHelper.update_value_type(ref _mid, _settings.mid_break_line.show ? _owner._get_mid_market_break() : double.NaN);
|
||||
session_low_dirty = ObjectHelper.update_value_type(ref _session_low, (_settings.session_low_line.show || _settings.session_range_fill.show) ? _owner._get_session_low() : double.NaN);
|
||||
session_high_dirty = ObjectHelper.update_value_type(ref _session_high, (_settings.session_high_line.show || _settings.session_range_fill.show) ? _owner._get_session_high() : double.NaN);
|
||||
bid_dirty = ConvertUtils.update_value_type(ref _bid, _settings.bid_break_line.show ? _owner._get_bid_market_break() : double.NaN);
|
||||
ask_dirty = ConvertUtils.update_value_type(ref _ask, _settings.ask_break_line.show ? _owner._get_ask_market_break() : double.NaN);
|
||||
mid_dirty = ConvertUtils.update_value_type(ref _mid, _settings.mid_break_line.show ? _owner._get_mid_market_break() : double.NaN);
|
||||
session_low_dirty = ConvertUtils.update_value_type(ref _session_low, (_settings.session_low_line.show || _settings.session_range_fill.show) ? _owner._get_session_low() : double.NaN);
|
||||
session_high_dirty = ConvertUtils.update_value_type(ref _session_high, (_settings.session_high_line.show || _settings.session_range_fill.show) ? _owner._get_session_high() : double.NaN);
|
||||
if (session_low_dirty)
|
||||
_low_index = null;
|
||||
if (session_high_dirty)
|
||||
@@ -871,7 +871,7 @@ namespace mbts.spark {
|
||||
else new_origin = mid;
|
||||
if (double.IsNaN(new_origin))
|
||||
new_origin = _owner._get_bid_market_break();
|
||||
origin_dirty = ObjectHelper.update_value_type(ref _origin, new_origin);
|
||||
origin_dirty = ConvertUtils.update_value_type(ref _origin, new_origin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,13 +259,13 @@ namespace mbts.ui {
|
||||
}
|
||||
|
||||
public static PropertyChangedCallback prop_changed_callback<TValue, TOwner>(PropertyChangedCallback<TValue, TOwner> callback) =>
|
||||
(d, e) => callback(ObjectHelper.try_convert<TOwner>(d), ObjectHelper.try_convert<TValue>(e.OldValue), ObjectHelper.try_convert<TValue>(e.NewValue));
|
||||
(d, e) => callback(ConvertUtils.try_convert<TOwner>(d), ConvertUtils.try_convert<TValue>(e.OldValue), ConvertUtils.try_convert<TValue>(e.NewValue));
|
||||
|
||||
public static PropertyChangedCallback prop_changed_callback<TValue, TOwner>(Action<TOwner, TValue> callback) =>
|
||||
(d, e) => callback(ObjectHelper.try_convert<TOwner>(d), ObjectHelper.try_convert<TValue>(e.NewValue));
|
||||
(d, e) => callback(ConvertUtils.try_convert<TOwner>(d), ConvertUtils.try_convert<TValue>(e.NewValue));
|
||||
|
||||
public static CoerceValueCallback coerce_value_callback<TValue, TOwner>(Func<TOwner, TValue, TValue> coerce_value) =>
|
||||
(d, obj) => coerce_value(ObjectHelper.try_convert<TOwner>(d), ObjectHelper.try_convert<TValue>(obj));
|
||||
(d, obj) => coerce_value(ConvertUtils.try_convert<TOwner>(d), ConvertUtils.try_convert<TValue>(obj));
|
||||
|
||||
public static double control_base_width(Thickness border_thickness, Thickness padding) =>
|
||||
border_thickness.Left + padding.Left + padding.Right + border_thickness.Right;
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace mbts.utils {
|
||||
public NonGenericComparerWrapper(IComparer<T> comparer) => _comparer = comparer;
|
||||
|
||||
public int Compare(object x, object y) =>
|
||||
_comparer.Compare(ObjectHelper.try_convert<T>(x), ObjectHelper.try_convert<T>(y));
|
||||
_comparer.Compare(ConvertUtils.try_convert<T>(x), ConvertUtils.try_convert<T>(y));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
|
||||
namespace System
|
||||
{
|
||||
public static class ObjectHelper
|
||||
{
|
||||
namespace System {
|
||||
public static class ConvertUtils {
|
||||
public static object try_convert(Type type, object obj) {
|
||||
try_convert(type, obj, out object result);
|
||||
return result;
|
||||
|
||||
Reference in new issue
Block a user