PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Converters/TwoValuesMultiConverter.cs

#
C# | 40 lines | 33 code | 7 blank | 0 comment | 6 complexity | fa8e8aac853ab9cb81e7af46fa06e601 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Data;
  6. using System.Windows;
  7. namespace Microsoft.Research.DynamicDataDisplay.Converters
  8. {
  9. public abstract class TwoValuesMultiConverter<T1, T2> : IMultiValueConverter
  10. {
  11. #region IMultiValueConverter Members
  12. public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  13. {
  14. if (values != null && values.Length == 2)
  15. {
  16. if (values[0] is T1 && values[1] is T2)
  17. {
  18. T1 param1 = (T1)values[0];
  19. T2 param2 = (T2)values[1];
  20. var result = ConvertCore(param1, param2, targetType, parameter, culture);
  21. return result;
  22. }
  23. }
  24. return DependencyProperty.UnsetValue;
  25. }
  26. protected abstract object ConvertCore(T1 value1, T2 value2, Type targetType, object parameter, System.Globalization.CultureInfo culture);
  27. public virtual object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
  28. {
  29. throw new NotSupportedException();
  30. }
  31. #endregion
  32. }
  33. }