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
38
public
object
Convert
(
object
Value)
39
{
40
if
(Value is
IPhysicalQuantity
PQ)
41
{
42
PhysicalQuantity
Q = PQ.
ToPhysicalQuantity
();
43
return
new
PersistableQuantity
(Q.
Magnitude
, Q.
Unit
.ToString(),
CommonTypes
.
GetNrDecimals
(Q.
Magnitude
));
44
}
45
else
46
throw
new
ArgumentException(
"Not a PhysicalQuantity."
, nameof(Value));
47
}
48
56
public
IElement
ConvertToElement
(
object
Value)
57
{
58
if
(Value is
IPhysicalQuantity
PQ)
59
{
60
PhysicalQuantity
Q = PQ.
ToPhysicalQuantity
();
61
return
new
ObjectValue
(
new
PersistableQuantity
(Q.
Magnitude
, Q.
Unit
.ToString(),
CommonTypes
.
GetNrDecimals
(Q.
Magnitude
)));
62
}
63
else
64
throw
new
ArgumentException(
"Not a PhysicalQuantity."
, nameof(Value));
65
}
66
}
67
}
Waher.Content.CommonTypes
Helps with parsing of commong data types.
Definition:
CommonTypes.cs:13
Waher.Content.CommonTypes.GetNrDecimals
static byte GetNrDecimals(double x)
Calculates the number of decimals of a floating-point number.
Definition:
CommonTypes.cs:903
Waher.Script.Objects.ObjectValue
Object value.
Definition:
ObjectValue.cs:12
Waher.Script.Objects.PhysicalQuantity
Physical quantity.
Definition:
PhysicalQuantity.cs:14
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:54
Waher.Script.Objects.PhysicalQuantity.Magnitude
double Magnitude
Magnitude
Definition:
PhysicalQuantity.cs:45
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.Convert
object Convert(object Value)
Converts the object in Value to an object of type To.
Definition:
PhysicalQuantityToPersistableQuantity.cs:38
Waher.Things.TypeConverters.PhysicalQuantityToPersistableQuantity.ConvertToElement
IElement ConvertToElement(object Value)
Converts the object in Value to an object of type To, encapsulated in an IElement.
Definition:
PhysicalQuantityToPersistableQuantity.cs:56
Waher.Things.TypeConverters.PhysicalQuantityToPersistableQuantity.To
Type To
Converter converts objects to this type.
Definition:
PhysicalQuantityToPersistableQuantity.cs:30
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:20
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:10
Waher.Content
Definition:
Array.cs:6
Waher.Script.Abstraction.Elements
Definition:
AbelianGroupElement.cs:5
Waher.Script.Objects
Definition:
BooleanValue.cs:7
Waher.Script.TypeConversion
Definition:
BigIntegerToDouble.cs:7
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