Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
StringToBoolean.cs
1using System;
4
6{
11 {
15 public Type From => typeof(string);
16
20 public Type To => typeof(bool);
21
27 public double Weight => 0.9;
28
35 public bool TryConvert(object Value, out object Result)
36 {
37 if (Value is string s)
38 {
39 switch (s.ToLower())
40 {
41 case "1":
42 case "true":
43 case "yes":
44 case "on":
45 Result = true;
46 return true;
47
48 case "0":
49 case "false":
50 case "no":
51 case "off":
52 Result = false;
53 return true;
54 }
55 }
56
57 Result = null;
58 return false;
59 }
60
68 public bool TryConvertToElement(object Value, out IElement Result)
69 {
70 if (this.TryConvert(Value, out object d) && d is bool b)
71 {
72 Result = new BooleanValue(b);
73 return true;
74 }
75
76 Result = null;
77 return false;
78 }
79 }
80}
Boolean-valued number.
Definition: BooleanValue.cs:12
bool TryConvert(object Value, out object Result)
Converts the object in Value to an object of type To.
double Weight
Weight of the converter. An estimate of how well the converter performs, or how much information is r...
Type To
Converter converts objects to this type.
Type From
Converts string values to Boolean values.
bool TryConvertToElement(object Value, out IElement Result)
Converts the object in Value to an object of type To, encapsulated in an IElement.
Basic interface for all types of elements.
Definition: IElement.cs:21
Converts an object of one type to an object of another type.