PageRenderTime 19ms CodeModel.GetById 9ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/V4/StockTrader 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//===================================================================================
17using System;
18using System.Collections.Generic;
19using System.Linq;
20using System.Text;
21using System.Windows.Data;
22using System.Globalization;
23
24namespace StockTraderRI.Infrastructure.Converters
25{
26    public class EnumToBooleanConverter : IValueConverter
27    {
28        #region IValueConverter Members
29
30        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
31        {
32            if (value == null || parameter == null)
33                return false;
34
35            return value.Equals(parameter);
36        }
37
38        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
39        {
40            if (value == null || parameter == null)
41                return null;
42
43            if ((bool)value)
44                return parameter;
45            
46            return null;
47        }
48        #endregion
49    }
50}