Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PhysicalQuantityToPersistableQuantity.cs
1
using
System
;
2
using
Waher.Content
;
3
using
Waher.Script.Abstraction.Elements
;
4
using
Waher.Script.Objects
;
5
using
Waher.Script.TypeConversion
;
6
using
Waher.Things.SensorData
;
7
8
namespace
Waher.Things.TypeConverters
9
{
13
public
class
PhysicalQuantityToPersistableQuantity
:
ITypeConverter
14
{
18
public
PhysicalQuantityToPersistableQuantity
()
19
{
20
}
21
25
public
Type
From
=> typeof(
PhysicalQuantity
);
26
30
public
Type
To
=> typeof(
PersistableQuantity
);
31
37
public
double
Weight
=> 1.0;
38
45
public
bool
TryConvert
(
object
Value, out
object
Result)
46
{
47
if
(Value is
IPhysicalQuantity
PQ)
48
{
49
PhysicalQuantity
Q = PQ.
ToPhysicalQuantity
();
50
Result =
new
PersistableQuantity
(Q.
Magnitude
, Q.
Unit
.ToString(),
CommonTypes
.
GetNrDecimals
(Q.
Magnitude
));
51
return
true
;
52
}
53
else
54
{
55
Result =
null
;
56
return
false
;
57
}
58
}
59
67
public
bool
TryConvertToElement
(
object
Value, out
IElement
Result)
68
{
69
if
(Value is
IPhysicalQuantity
PQ)
70
{
71
PhysicalQuantity
Q = PQ.
ToPhysicalQuantity
();
72
Result =
new
ObjectValue
(
new
PersistableQuantity
(Q.
Magnitude
, Q.
Unit
.ToString(),
CommonTypes
.
GetNrDecimals
(Q.
Magnitude
)));
73
return
true
;
74
}
75
else
76
{
77
Result =
null
;
78
return
false
;
79
}
80
}
81
}
82
}
Waher.Content.CommonTypes
Helps with parsing of commong data types.
Definition:
CommonTypes.cs:15
Waher.Content.CommonTypes.GetNrDecimals
static byte GetNrDecimals(double x)
Calculates the number of decimals of a floating-point number.
Definition:
CommonTypes.cs:905
Waher.Script.Objects.ObjectValue
Object value.
Definition:
ObjectValue.cs:14
Waher.Script.Objects.PhysicalQuantity
Physical quantity.
Definition:
PhysicalQuantity.cs:15
Waher.Script.Objects.PhysicalQuantity.ToPhysicalQuantity
PhysicalQuantity ToPhysicalQuantity()
Converts underlying object to a physical quantity.
Waher.Script.Objects.PhysicalQuantity.Unit
Unit Unit
Unit
Definition:
PhysicalQuantity.cs:55
Waher.Script.Objects.PhysicalQuantity.Magnitude
double Magnitude
Magnitude
Definition:
PhysicalQuantity.cs:46
Waher.Things.SensorData.PersistableQuantity
Persistable quantity object.
Definition:
PersistableQuantity.cs:15
Waher.Things.TypeConverters.PhysicalQuantityToPersistableQuantity
Converts a PhysicalQuantity to a PersistableQuantity.
Definition:
PhysicalQuantityToPersistableQuantity.cs:14
Waher.Things.TypeConverters.PhysicalQuantityToPersistableQuantity.Weight
double Weight
Weight of the converter. An estimate of how well the converter performs, or how much information is r...
Definition:
PhysicalQuantityToPersistableQuantity.cs:37
Waher.Things.TypeConverters.PhysicalQuantityToPersistableQuantity.To
Type To
Converter converts objects to this type.
Definition:
PhysicalQuantityToPersistableQuantity.cs:30
Waher.Things.TypeConverters.PhysicalQuantityToPersistableQuantity.TryConvert
bool TryConvert(object Value, out object Result)
Converts the object in Value to an object of type To.
Definition:
PhysicalQuantityToPersistableQuantity.cs:45
Waher.Things.TypeConverters.PhysicalQuantityToPersistableQuantity.TryConvertToElement
bool TryConvertToElement(object Value, out IElement Result)
Converts the object in Value to an object of type To, encapsulated in an IElement.
Definition:
PhysicalQuantityToPersistableQuantity.cs:67
Waher.Things.TypeConverters.PhysicalQuantityToPersistableQuantity.From
Type From
Converter converts objects of this type.
Definition:
PhysicalQuantityToPersistableQuantity.cs:25
Waher.Things.TypeConverters.PhysicalQuantityToPersistableQuantity.PhysicalQuantityToPersistableQuantity
PhysicalQuantityToPersistableQuantity()
Converts a PhysicalQuantity to a PersistableQuantity.
Definition:
PhysicalQuantityToPersistableQuantity.cs:18
Waher.Script.Abstraction.Elements.IElement
Basic interface for all types of elements.
Definition:
IElement.cs:21
Waher.Script.Objects.IPhysicalQuantity
Interface for objects that can be represented as a physical quantity.
Definition:
IPhysicalQuantity.cs:7
Waher.Script.TypeConversion.ITypeConverter
Converts an object of one type to an object of another type.
Definition:
ITypeConverter.cs:11
System
Definition:
Adapters.g.cs:58
Waher.Content
Definition:
Array.cs:6
Waher.Script.Abstraction.Elements
Definition:
AbelianGroupElement.cs:4
Waher.Script.Objects
Definition:
BooleanValue.cs:7
Waher.Script.TypeConversion
Definition:
ConversionSequence.cs:5
Waher.Things.SensorData
Definition:
BooleanField.cs:6
Waher.Things.TypeConverters
Definition:
BooleanFieldToString.cs:8
IoTGateway
Things
Waher.Things
TypeConverters
PhysicalQuantityToPersistableQuantity.cs
Generated by
1.9.5