Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
BooleanValue.cs
1using System;
2using System.Reflection;
5
7{
11 public sealed class BooleanValue : FieldElement
12 {
13 private static readonly BooleanValues associatedField = new BooleanValues();
14
15 private bool value;
16
21 public BooleanValue(bool Value)
22 {
23 this.value = Value;
24 }
25
29 public bool Value
30 {
31 get => this.value;
32 set => this.value = value;
33 }
34
36 public override string ToString()
37 {
38 return Expression.ToString(this.value);
39 }
40
44 public override IField AssociatedField
45 {
46 get { return associatedField; }
47 }
48
52 public override object AssociatedObjectValue => this.value;
53
60 {
61 if (!(Element.AssociatedObjectValue is bool b))
62 return null;
63 else
64 return new BooleanValue(this.value && b);
65 }
66
71 public override IRingElement Invert()
72 {
73 return new BooleanValue(this.value);
74 }
75
82 {
83 if (!(Element.AssociatedObjectValue is bool b))
84 return null;
85 else
86 return new BooleanValue(this.value ^ b);
87 }
88
93 public override IGroupElement Negate()
94 {
95 return new BooleanValue(this.value);
96 }
97
99 public override bool Equals(object obj)
100 {
101 if (!(obj is IElement E) || !(E.AssociatedObjectValue is bool b))
102 return false;
103 else
104 return this.value == b;
105 }
106
108 public override int GetHashCode()
109 {
110 return this.value.GetHashCode();
111 }
112
116 public static readonly BooleanValue True = new BooleanValue(true);
117
121 public static readonly BooleanValue False = new BooleanValue(false);
122
127 {
128 get { return False; }
129 }
130
135 {
136 get { return True; }
137 }
138
145 public override bool TryConvertTo(Type DesiredType, out object Value)
146 {
147 if (DesiredType == typeof(bool))
148 {
149 Value = this.value;
150 return true;
151 }
152 else if (DesiredType.GetTypeInfo().IsAssignableFrom(typeof(bool).GetTypeInfo()))
153 {
154 Value = this.value;
155 return true;
156 }
157 else
158 return Expression.TryConvert(this.value, DesiredType, out Value);
159 }
160 }
161}
Base class for all types of elements.
Definition: Element.cs:13
abstract object AssociatedObjectValue
Associated object value.
Definition: Element.cs:46
Base class for all types of field elements.
Definition: FieldElement.cs:10
Class managing a script expression.
Definition: Expression.cs:39
static bool TryConvert(object Value, Type DesiredType, out object Result)
Tries to convert an object Value to an object of type DesiredType .
Definition: Expression.cs:5268
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Definition: Expression.cs:4496
Boolean-valued number.
Definition: BooleanValue.cs:12
override IGroupElement Negate()
Negates the element.
Definition: BooleanValue.cs:93
override object AssociatedObjectValue
Associated object value.
Definition: BooleanValue.cs:52
override bool Equals(object obj)
Compares the element to another. If elements are equal.
Definition: BooleanValue.cs:99
override int GetHashCode()
Calculates a hash code of the element. Hash code.
BooleanValue(bool Value)
Boolean-valued number.
Definition: BooleanValue.cs:21
override ICommutativeRingWithIdentityElement One
Returns the identity element of the commutative ring with identity.
static readonly BooleanValue False
Constant false value.
override IField AssociatedField
Associated Field.
Definition: BooleanValue.cs:45
override IRingElement Invert()
Inverts the element, if possible.
Definition: BooleanValue.cs:71
override bool TryConvertTo(Type DesiredType, out object Value)
Converts the value to a .NET type.
override ICommutativeRingElement Multiply(ICommutativeRingElement Element)
Tries to multiply an element to the current element.
Definition: BooleanValue.cs:59
override IAbelianGroupElement Add(IAbelianGroupElement Element)
Tries to add an element to the current element.
Definition: BooleanValue.cs:81
static readonly BooleanValue True
Constant true value.
override IAbelianGroupElement Zero
Returns the zero element of the group.
The field Z_2 of boolean numbers ([0]_2, 0 or false, and [1]_2, 1 or true).
Basic interface for all types of abelian group elements.
Basic interface for all types of commutative ring elements.
Basic interface for all types of commutative ring with identity elements.
Basic interface for all types of elements.
Definition: IElement.cs:20
Basic interface for all types of group elements.
Definition: IGroupElement.cs:9
Basic interface for all types of ring elements.
Definition: IRingElement.cs:10
Basic interface for all types of fields.
Definition: IField.cs:9