Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NumberToBoolConverter.cs
1using System.Globalization;
2
4{
5 public class NumberToBoolConverter : IValueConverter
6 {
16 public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
17 {
18 if (value is null)
19 return false;
20
21 try
22 {
23 // Convert the incoming value to a double. This handles common numeric types.
24 double NumericValue = 0;
25
26 NumericValue = value switch
27 {
28 int Int => Int,
29 long Long => Long,
30 float Float => (double)Float,
31 double Double => Double,
32 decimal Dec => (double)Dec,
33 short Short => Short,
34 byte Byte => Byte,
35 sbyte Sbyte => Sbyte,
36 uint Uint => Uint,
37 ushort Ushort => Ushort,
38 ulong Ulong => Ulong,
39 _ => System.Convert.ToDouble(value, culture),// If the value is not a recognized numeric type,
40 // attempt a generic conversion.
41 };
42
43 // If the numeric value is nonzero, return true; otherwise, false.
44 return NumericValue != 0.0;
45 }
46 catch
47 {
48 return false;
49 }
50 }
51
55 public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
56 {
57 throw new NotImplementedException();
58 }
59 }
60}
object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
Converts a numeric value (decimal, double, etc.) into a boolean. Returns true if the numeric value is...
object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
ConvertBack is not implemented.
Definition: ImplTypes.g.cs:58