123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Globalization;
- using System.Linq;
- namespace InABox.WPF
- {
-
- public abstract class AbstractNumericArrayConverter<TValue> : TypeConverter
- {
- protected abstract TValue[] Convert(IEnumerable<string> values);
-
- public override object ConvertFrom(
- ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- if (value is string list)
- {
- try
- {
- var result = Convert(list.Split(','));
- return result;
- }
- catch
- {
-
- }
- }
- return new TValue[] { };
- }
-
- public override bool CanConvertFrom(
- ITypeDescriptorContext context, Type sourceType)
- {
- if (sourceType == typeof(string))
- return true;
-
- return base.CanConvertFrom(context, sourceType);
- }
- }
-
- public abstract class AbstractNumericCalculator<TValue,TFunction> : AbstractCalculator<TValue, TFunction, NumericCalculatorType>
- where TFunction : AbstractCalculatorFunction<TValue,NumericCalculatorType>, new()
-
- {
- public abstract TValue[]? Constants { get; set; }
-
- protected override TValue Convert(IEnumerable<TValue> value, object parameter = null)
- {
- var enumerable = value as TValue[] ?? value.ToArray();
- var values = Constants != null
- ? Constants.Concat(enumerable.ToArray())
- : enumerable;
- return base.Convert(values, parameter);
- }
- }
- }
|