Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PhysicalQuantityToPersistableQuantity.cs
1using System;
2using Waher.Content;
7
9{
14 {
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 {
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 {
73 return true;
74 }
75 else
76 {
77 Result = null;
78 return false;
79 }
80 }
81 }
82}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:15
static byte GetNrDecimals(double x)
Calculates the number of decimals of a floating-point number.
Definition: CommonTypes.cs:905
PhysicalQuantity ToPhysicalQuantity()
Converts underlying object to a physical quantity.
double Weight
Weight of the converter. An estimate of how well the converter performs, or how much information is r...
bool TryConvert(object Value, out object Result)
Converts the object in Value to an object of type To.
bool TryConvertToElement(object Value, out IElement Result)
Converts the object in Value to an object of type To, encapsulated in an IElement.
PhysicalQuantityToPersistableQuantity()
Converts a PhysicalQuantity to a PersistableQuantity.
Basic interface for all types of elements.
Definition: IElement.cs:21
Interface for objects that can be represented as a physical quantity.
Converts an object of one type to an object of another type.