PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/V2/trunk/RI/Desktop/StockTraderRI.Infrastructure/Converters/EnumToBooleanConverter.Desktop.cs

#
C# | 50 lines | 28 code | 6 blank | 16 comment | 9 complexity | 2082f724a9c1691583c7124687a955f1 MD5 | raw file
  1. //===================================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4. //===================================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===================================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===================================================================================
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Windows.Data;
  22. using System.Globalization;
  23. namespace StockTraderRI.Infrastructure.Converters
  24. {
  25. public class EnumToBooleanConverter : IValueConverter
  26. {
  27. #region IValueConverter Members
  28. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  29. {
  30. if (value == null || parameter == null)
  31. return false;
  32. return value.Equals(parameter);
  33. }
  34. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  35. {
  36. if (value == null || parameter == null)
  37. return null;
  38. if ((bool)value)
  39. return parameter;
  40. return null;
  41. }
  42. #endregion
  43. }
  44. }