[runtime] Fix corlib out of date error with disabled COM
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / Editors / NonZeroToBoolConverter.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Editors 
5 {
6     using System;
7     using System.Collections;
8     using System.Diagnostics;
9     using System.Diagnostics.CodeAnalysis;
10     using System.Globalization;
11     using System.Windows.Data;
12     using System.Activities.Presentation;
13
14     // <summary>
15     // Converts ints >0 to true, everything else to false.  This class is instantiated from XAML.
16     // </summary>
17     [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
18     internal class NonZeroToBoolConverter : IValueConverter 
19     {
20
21         private bool _invert;
22
23         // <summary>
24         // If set to false, NonZeroToBoolConverter.Convert() converts 0 to false and !0 to true.
25         // If set to true, the result is inverted.
26         // </summary>
27         [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
28         public bool Invert 
29         {
30             get { return _invert; }
31             set { _invert = value; }
32         }
33
34         public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
35         {
36             if (targetType == typeof(bool) && value is int) 
37             {
38                 return (((int)value) > 0) ^ _invert;
39             }
40
41             return false;
42         }
43
44         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
45         {
46             throw FxTrace.Exception.AsError(new NotImplementedException());
47         }
48     }
49 }