2using System.Collections.Generic;
3using System.Reflection;
16 private readonly
Prefix prefix;
17 private readonly ICollection<KeyValuePair<AtomicUnit, int>> factors;
18 private bool hasBaseUnits =
false;
19 private bool hasReferenceUnits =
false;
53 KeyValuePair<AtomicUnit, int>[] Factors2 =
new KeyValuePair<AtomicUnit, int>[c];
55 for (i = 0; i < c; i++)
58 this.factors = Factors2;
66 : this(
Prefix.None, AtomicUnits)
76 : this(
Prefix, Prepare(AtomicUnits))
80 private static KeyValuePair<AtomicUnit, int>[] Prepare(
AtomicUnit[] AtomicUnits)
82 int i, c = AtomicUnits.Length;
83 KeyValuePair<AtomicUnit, int>[] Result =
new KeyValuePair<AtomicUnit, int>[c];
85 for (i = 0; i < c; i++)
86 Result[i] =
new KeyValuePair<AtomicUnit, int>(AtomicUnits[i], 1);
95 public Unit(params
string[] AtomicUnits)
96 : this(
Prefix.None, AtomicUnits)
109 int i, c = AtomicUnits.Length;
110 KeyValuePair<AtomicUnit, int>[]
Factors =
new KeyValuePair<AtomicUnit, int>[c];
112 for (i = 0; i < c; i++)
113 Factors[i] =
new KeyValuePair<AtomicUnit, int>(
new AtomicUnit(AtomicUnits[i]), 1);
128 throw new Exceptions.ScriptException(
"Unable to parse unit: " + UnitString);
140 int Len = UnitString?.Length ?? 0;
142 if (!
TryParse(UnitString, ref Pos, Len,
true, out
Unit))
151 private static bool TryParse(
string UnitString, ref
int Pos,
int Len,
bool PermitPrefix, out
Unit Unit)
158 LinkedList<KeyValuePair<AtomicUnit, int>>
Factors =
new LinkedList<KeyValuePair<AtomicUnit, int>>();
159 KeyValuePair<Prefix, KeyValuePair<AtomicUnit, int>[]> CompoundFactors;
160 bool HasCompoundFactors;
161 string Name, Name2, s;
165 char ch = UnitString[Pos++];
166 bool LastDivision =
false;
170 if (ch ==
'd' && Pos < Len && UnitString[Pos] ==
'a')
175 else if (!Prefixes.TryParsePrefix(ch, out
Prefix))
179 ch = Pos < Len ? UnitString[Pos++] : (char)0;
191 ch = Pos < Len ? UnitString[Pos++] : (char)0;
196 ch = Pos < Len ? UnitString[Pos++] : (char)0;
197 while (ch > 0 && (ch <=
' ' || ch == 160))
198 ch = Pos < Len ? UnitString[Pos++] : (
char)0;
201 while (
char.IsLetter(ch) || ch ==
'(' || ch ==
'°')
205 if (!
TryParse(UnitString, ref Pos, Len,
false, out Unit Unit2))
208 ch = Pos < Len ? UnitString[Pos++] : (char)0;
209 while (ch > 0 && (ch <=
' ' || ch == 160))
210 ch = Pos < Len ? UnitString[Pos++] : (
char)0;
215 ch = Pos < Len ? UnitString[Pos++] : (char)0;
216 while (ch > 0 && (ch <=
' ' || ch == 160))
217 ch = Pos < Len ? UnitString[Pos++] : (
char)0;
221 ch = Pos < Len ? UnitString[Pos++] : (char)0;
222 while (ch > 0 && (ch <=
' ' || ch == 160))
223 ch = Pos < Len ? UnitString[Pos++] : (
char)0;
225 if (ch ==
'-' ||
char.IsDigit(ch))
230 ch = Pos < Len ? UnitString[Pos++] : (char)0;
232 while (
char.IsDigit(ch))
233 ch = Pos < Len ? UnitString[Pos++] : (
char)0;
236 s = UnitString.Substring(i, Pos - i);
238 s = UnitString.Substring(i, Pos - i - 1);
249 ch = Pos < Len ? UnitString[Pos++] : (char)0;
254 ch = Pos < Len ? UnitString[Pos++] : (char)0;
261 foreach (KeyValuePair<AtomicUnit, int> Factor
in Unit2.Factors)
262 Factors.AddLast(
new KeyValuePair<AtomicUnit, int>(Factor.Key, -Factor.Value * Exponent));
266 foreach (KeyValuePair<AtomicUnit, int> Factor
in Unit2.Factors)
267 Factors.AddLast(
new KeyValuePair<AtomicUnit, int>(Factor.Key, Factor.Value * Exponent));
273 ch = Pos < Len ? UnitString[Pos++] : (char)0;
275 while (
char.IsLetter(ch))
276 ch = Pos < Len ? UnitString[Pos++] : (
char)0;
279 Name = UnitString.Substring(i, Pos - i);
281 Name = UnitString.Substring(i, Pos - i - 1);
285 if (
Expression.keywords.ContainsKey(Name2 = UnitString.Substring(Start, i - Start) + Name))
287 else if (HasCompoundFactors = TryGetCompoundUnit(Name2, out CompoundFactors))
289 Prefix = CompoundFactors.Key;
292 else if (ContainsDerivedOrBaseUnit(Name2))
298 HasCompoundFactors = TryGetCompoundUnit(Name, out CompoundFactors);
301 HasCompoundFactors = TryGetCompoundUnit(Name, out CompoundFactors);
303 while (ch > 0 && (ch <=
' ' || ch == 160))
304 ch = Pos < Len ? UnitString[Pos++] : (char)0;
308 ch = Pos < Len ? UnitString[Pos++] : (char)0;
309 while (ch > 0 && (ch <=
' ' || ch == 160))
310 ch = Pos < Len ? UnitString[Pos++] : (
char)0;
312 if (ch ==
'-' ||
char.IsDigit(ch))
317 ch = Pos < Len ? UnitString[Pos++] : (char)0;
319 while (
char.IsDigit(ch))
320 ch = Pos < Len ? UnitString[Pos++] : (
char)0;
323 s = UnitString.Substring(i, Pos - i);
325 s = UnitString.Substring(i, Pos - i - 1);
336 ch = Pos < Len ? UnitString[Pos++] : (char)0;
341 ch = Pos < Len ? UnitString[Pos++] : (char)0;
346 if (HasCompoundFactors)
350 foreach (KeyValuePair<AtomicUnit, int> Segment
in CompoundFactors.Value)
351 Factors.AddLast(
new KeyValuePair<AtomicUnit, int>(Segment.Key, -Segment.Value * Exponent));
355 foreach (KeyValuePair<AtomicUnit, int> Segment
in CompoundFactors.Value)
356 Factors.AddLast(
new KeyValuePair<AtomicUnit, int>(Segment.Key, Segment.Value * Exponent));
362 Factors.AddLast(
new KeyValuePair<AtomicUnit, int>(
new AtomicUnit(Name), -Exponent));
364 Factors.AddLast(
new KeyValuePair<AtomicUnit, int>(
new AtomicUnit(Name), Exponent));
368 while (ch > 0 && (ch <=
' ' || ch == 160))
369 ch = Pos < Len ? UnitString[Pos++] : (
char)0;
371 if (ch ==
'*' || ch ==
'⋅')
372 LastDivision =
false;
385 ch = Pos < Len ? UnitString[Pos++] : (char)0;
386 while (ch > 0 && (ch <=
' ' || ch == 160))
387 ch = Pos < Len ? UnitString[Pos++] : (
char)0;
390 PermitPrefix =
false;
409 public ICollection<KeyValuePair<AtomicUnit, int>>
Factors => this.factors;
418 return this.prefix == Prefix.None && this.factors.Count == 0;
429 return this.factors.Count > 0;
447 LinkedList<KeyValuePair<AtomicUnit, int>>
Factors =
new LinkedList<KeyValuePair<AtomicUnit, int>>();
449 foreach (KeyValuePair<AtomicUnit, int> Factor
in this.factors)
450 Factors.AddLast(
new KeyValuePair<AtomicUnit, int>(Factor.Key, -Factor.Value));
458 if (!(obj is
Unit U))
461 return this.
Equals(U,
true);
472 if (CheckPrefix && this.prefix != Unit2.prefix)
475 if (this.factors.Count != Unit2.factors.Count)
481 foreach (KeyValuePair<AtomicUnit, int> Factor
in this.factors)
483 Name = Factor.Key.Name;
486 foreach (KeyValuePair<AtomicUnit, int> Factor2
in Unit2.factors)
488 if (Name == Factor2.Key.Name)
490 if (Factor.Value != Factor2.Value)
508 int i = (int)this.prefix;
510 foreach (KeyValuePair<AtomicUnit, int> Factor
in this.factors)
511 i ^= Factor.Key.GetHashCode() ^ Factor.Value.GetHashCode();
528 StringBuilder Numerator =
null;
529 StringBuilder Denominator =
null;
530 int NrDenominators = 0;
532 foreach (KeyValuePair<AtomicUnit, int> Factor
in this.factors)
534 if (Factor.Value > 0)
536 if (Numerator is
null)
541 Numerator =
new StringBuilder();
544 Numerator.Append(
'⋅');
546 Numerator.Append(Factor.Key.Name);
548 if (Factor.Value > 1)
550 if (Factor.Value == 2)
551 Numerator.Append(
'²');
552 else if (Factor.Value == 3)
553 Numerator.Append(
'³');
556 Numerator.Append(
'^');
557 Numerator.Append(Factor.Value.ToString());
563 if (Denominator is
null)
564 Denominator =
new StringBuilder();
566 Denominator.Append(
'⋅');
569 Denominator.Append(Factor.Key.Name);
571 if (Factor.Value < -1)
573 if (Factor.Value == -2)
574 Denominator.Append(
'²');
575 else if (Factor.Value == -3)
576 Denominator.Append(
'³');
579 Denominator.Append(
'^');
580 Denominator.Append((-Factor.Value).ToString());
586 if (Numerator is
null)
591 Numerator =
new StringBuilder();
594 if (!(Denominator is
null))
596 Numerator.Append(
'/');
598 if (NrDenominators > 1)
599 Numerator.Append(
'(');
601 Numerator.Append(Denominator.ToString());
603 if (NrDenominators > 1)
604 Numerator.Append(
')');
607 return Numerator.ToString();
619 LinkedList<KeyValuePair<AtomicUnit, int>> Result =
new LinkedList<KeyValuePair<AtomicUnit, int>>();
622 int ResultExponent = LeftExponent + RightExponent;
624 LinkedListNode<KeyValuePair<AtomicUnit, int>> Loop;
629 foreach (KeyValuePair<AtomicUnit, int> Factor
in Left.factors)
630 Result.AddLast(Factor);
632 foreach (KeyValuePair<AtomicUnit, int> Factor
in Right.factors)
634 Name = Factor.Key.Name;
638 while (!(Loop is
null) && !Found)
640 if (Loop.Value.Key.Name == Name)
643 Exponent = Loop.Value.Value + Factor.Value;
647 Loop.Value =
new KeyValuePair<AtomicUnit, int>(Loop.Value.Key, Exponent);
656 Result.AddLast(Factor);
659 return new Unit(ResultPrefix, Result);
671 LinkedList<KeyValuePair<AtomicUnit, int>> Result =
new LinkedList<KeyValuePair<AtomicUnit, int>>();
674 int ResultExponent = LeftExponent - RightExponent;
676 LinkedListNode<KeyValuePair<AtomicUnit, int>> Loop;
681 foreach (KeyValuePair<AtomicUnit, int> Factor
in Left.factors)
682 Result.AddLast(Factor);
684 foreach (KeyValuePair<AtomicUnit, int> Factor
in Right.factors)
686 Name = Factor.Key.Name;
690 while (!(Loop is
null) && !Found)
692 if (Loop.Value.Key.Name == Name)
695 Exponent = Loop.Value.Value - Factor.Value;
699 Loop.Value =
new KeyValuePair<AtomicUnit, int>(Loop.Value.Key, Exponent);
708 Result.AddLast(
new KeyValuePair<AtomicUnit, int>(Factor.Key, -Factor.Value));
711 return new Unit(ResultPrefix, Result);
721 if (this.hasBaseUnits)
726 if (baseUnits is
null)
729 bool HasNonBase =
false;
731 foreach (KeyValuePair<AtomicUnit, int> Factor
in this.factors)
733 if (!baseUnits.ContainsKey(Factor.Key.Name))
742 LinkedList<KeyValuePair<AtomicUnit, int>> BaseFactors =
new LinkedList<KeyValuePair<AtomicUnit, int>>();
747 foreach (KeyValuePair<AtomicUnit, int> Factor
in this.factors)
749 FactorExponent = Factor.Value;
751 if (baseUnits.ContainsKey(Name = Factor.Key.Name))
752 this.Add(BaseFactors, Factor.Key, Factor.Value);
755 Magnitude *= Math.Pow(Quantity.Magnitude, FactorExponent);
758 foreach (KeyValuePair<AtomicUnit, int> Segment
in Quantity.Unit.factors)
759 this.Add(BaseFactors, Segment.Key, Segment.Value * FactorExponent);
761 else if (compoundUnits.TryGetValue(Name, out KeyValuePair<
Prefix, KeyValuePair<AtomicUnit, int>[]> Units))
765 foreach (KeyValuePair<AtomicUnit, int> Segment
in Units.Value)
766 this.Add(BaseFactors, Segment.Key, Segment.Value * FactorExponent);
769 this.Add(BaseFactors, Factor.Key, Factor.Value);
773 if (FactorExponent != 0)
774 Magnitude *= Math.Pow(10, FactorExponent);
776 Result.hasBaseUnits =
true;
782 this.hasBaseUnits =
true;
790 LinkedListNode<KeyValuePair<AtomicUnit, int>> Loop =
Factors.First;
793 while (!(Loop is
null) && Loop.Value.Key.Name != Name)
799 Loop.Value =
new KeyValuePair<AtomicUnit, int>(
AtomicUnit, Loop.Value.Value + Exponent);
821 if (this.hasReferenceUnits)
826 if (baseUnits is
null)
829 bool HasNonReference =
false;
831 foreach (KeyValuePair<AtomicUnit, int> Factor
in this.factors)
833 if (!referenceUnits.ContainsKey(Factor.Key.Name))
835 HasNonReference =
true;
842 LinkedList<KeyValuePair<AtomicUnit, int>> ReferenceFactors =
new LinkedList<KeyValuePair<AtomicUnit, int>>();
847 foreach (KeyValuePair<AtomicUnit, int> Factor
in this.factors)
849 FactorExponent = Factor.Value;
851 if (referenceUnits.ContainsKey(Name = Factor.Key.Name))
852 this.Add(ReferenceFactors, Factor.Key, Factor.Value);
853 else if (baseUnits.TryGetValue(Name, out
IBaseQuantity BaseQuantity))
855 if (BaseQuantity.ToReferenceUnit(ref Magnitude, ref NrDecimals, Name, FactorExponent))
856 this.Add(ReferenceFactors, BaseQuantity.ReferenceUnit, FactorExponent);
858 this.Add(ReferenceFactors, Factor.Key, Factor.Value);
862 if (FactorExponent != 0)
864 double k = Math.Pow(Quantity.Magnitude, FactorExponent);
866 NrDecimals -= Math.Log10(k);
870 foreach (KeyValuePair<AtomicUnit, int> Segment
in Quantity.Unit.factors)
872 if (referenceUnits.ContainsKey(Name = Segment.Key.Name))
873 this.Add(ReferenceFactors, Segment.Key, Segment.Value * FactorExponent);
874 else if (baseUnits.TryGetValue(Name, out BaseQuantity))
876 if (BaseQuantity.ToReferenceUnit(ref Magnitude, ref NrDecimals, Name, Segment.Value * FactorExponent))
877 this.Add(ReferenceFactors, BaseQuantity.ReferenceUnit, Segment.Value * FactorExponent);
879 this.Add(ReferenceFactors, Segment.Key, Segment.Value * FactorExponent);
882 this.Add(ReferenceFactors, Segment.Key, Segment.Value * FactorExponent);
885 else if (compoundUnits.TryGetValue(Name, out KeyValuePair<
Prefix, KeyValuePair<AtomicUnit, int>[]> Units))
889 foreach (KeyValuePair<AtomicUnit, int> Segment
in Units.Value)
891 if (referenceUnits.ContainsKey(Name = Segment.Key.Name))
892 this.Add(ReferenceFactors, Segment.Key, Segment.Value * FactorExponent);
893 else if (baseUnits.TryGetValue(Name, out BaseQuantity))
895 if (BaseQuantity.ToReferenceUnit(ref Magnitude, ref NrDecimals, Name, Segment.Value * FactorExponent))
896 this.Add(ReferenceFactors, BaseQuantity.ReferenceUnit, Segment.Value * FactorExponent);
898 this.Add(ReferenceFactors, Segment.Key, Segment.Value * FactorExponent);
901 this.Add(ReferenceFactors, Segment.Key, Segment.Value * FactorExponent);
905 this.Add(ReferenceFactors, Factor.Key, Factor.Value);
909 if (FactorExponent != 0)
911 Magnitude *= Math.Pow(10, FactorExponent);
912 NrDecimals -= FactorExponent;
915 Result.hasBaseUnits =
true;
916 Result.hasReferenceUnits =
true;
922 this.hasBaseUnits =
true;
923 this.hasReferenceUnits =
true;
948 if (this.hasReferenceUnits)
953 if (baseUnits is
null)
956 bool HasNonReference =
false;
958 foreach (KeyValuePair<AtomicUnit, int> Factor
in this.factors)
960 if (!referenceUnits.ContainsKey(Factor.Key.Name))
962 HasNonReference =
true;
969 LinkedList<KeyValuePair<AtomicUnit, int>> ReferenceFactors =
new LinkedList<KeyValuePair<AtomicUnit, int>>();
974 foreach (KeyValuePair<AtomicUnit, int> Factor
in this.factors)
976 FactorExponent = Factor.Value;
978 if (referenceUnits.ContainsKey(Name = Factor.Key.Name))
979 this.Add(ReferenceFactors, Factor.Key, Factor.Value);
980 else if (baseUnits.TryGetValue(Name, out
IBaseQuantity BaseQuantity))
982 if (BaseQuantity.FromReferenceUnit(ref Magnitude, ref NrDecimals, Name, FactorExponent))
983 this.Add(ReferenceFactors, BaseQuantity.ReferenceUnit, FactorExponent);
985 this.Add(ReferenceFactors, Factor.Key, Factor.Value);
989 if (FactorExponent != 0)
991 double k = Math.Pow(Quantity.Magnitude, FactorExponent);
993 NrDecimals += Math.Log10(k);
997 foreach (KeyValuePair<AtomicUnit, int> Segment
in Quantity.Unit.factors)
999 if (referenceUnits.ContainsKey(Name = Segment.Key.Name))
1000 this.Add(ReferenceFactors, Segment.Key, Segment.Value * FactorExponent);
1001 else if (baseUnits.TryGetValue(Name, out BaseQuantity))
1003 if (BaseQuantity.FromReferenceUnit(ref Magnitude, ref NrDecimals, Name, Segment.Value * FactorExponent))
1004 this.Add(ReferenceFactors, BaseQuantity.ReferenceUnit, Segment.Value * FactorExponent);
1006 this.Add(ReferenceFactors, Segment.Key, Segment.Value * FactorExponent);
1009 this.Add(ReferenceFactors, Segment.Key, Segment.Value * FactorExponent);
1012 else if (compoundUnits.TryGetValue(Name, out KeyValuePair<
Prefix, KeyValuePair<AtomicUnit, int>[]> Units))
1016 foreach (KeyValuePair<AtomicUnit, int> Segment
in Units.Value)
1018 if (referenceUnits.ContainsKey(Name = Segment.Key.Name))
1019 this.Add(ReferenceFactors, Segment.Key, Segment.Value * FactorExponent);
1020 else if (baseUnits.TryGetValue(Name, out BaseQuantity))
1022 if (BaseQuantity.FromReferenceUnit(ref Magnitude, ref NrDecimals, Name, Segment.Value * FactorExponent))
1023 this.Add(ReferenceFactors, BaseQuantity.ReferenceUnit, Segment.Value * FactorExponent);
1025 this.Add(ReferenceFactors, Segment.Key, Segment.Value * FactorExponent);
1028 this.Add(ReferenceFactors, Segment.Key, Segment.Value * FactorExponent);
1032 this.Add(ReferenceFactors, Factor.Key, Factor.Value);
1036 if (FactorExponent != 0)
1038 Magnitude *= Math.Pow(10, FactorExponent);
1039 NrDecimals -= FactorExponent;
1042 Result.hasBaseUnits =
true;
1043 Result.hasReferenceUnits =
true;
1049 this.hasBaseUnits =
true;
1050 this.hasReferenceUnits =
true;
1056 private static void Search()
1058 Dictionary<string, IBaseQuantity> BaseUnits =
new Dictionary<string, IBaseQuantity>();
1059 Dictionary<string, IBaseQuantity> ReferenceUnits =
new Dictionary<string, IBaseQuantity>();
1060 Dictionary<string, KeyValuePair<Prefix, KeyValuePair<AtomicUnit, int>[]>> CompoundUnits =
new Dictionary<string, KeyValuePair<Prefix, KeyValuePair<AtomicUnit, int>[]>>();
1061 Dictionary<string, PhysicalQuantity> DerivedUnits =
new Dictionary<string, PhysicalQuantity>();
1076 catch (Exception ex)
1084 foreach (
string Unit
in BaseQuantity.
BaseUnits)
1085 BaseUnits[Unit] = BaseQuantity;
1098 catch (Exception ex)
1104 foreach (Tuple<
string,
Prefix, KeyValuePair<AtomicUnit, int>[]> CompoundUnit
in CompoundQuantity.
CompoundQuantities)
1105 CompoundUnits[CompoundUnit.Item1] =
new KeyValuePair<Prefix, KeyValuePair<AtomicUnit, int>[]>(CompoundUnit.Item2, CompoundUnit.Item3);
1118 catch (Exception ex)
1124 foreach (KeyValuePair<string, PhysicalQuantity> Derived
in DerivedQuantity.
DerivedUnits)
1125 DerivedUnits[Derived.Key] = Derived.Value;
1128 baseUnits = BaseUnits;
1129 referenceUnits = ReferenceUnits;
1130 compoundUnits = CompoundUnits;
1131 derivedUnits = DerivedUnits;
1134 private readonly
static Dictionary<string, IUnitCategory> categoryPerUnit =
new Dictionary<string, IUnitCategory>();
1135 private static Dictionary<string, IBaseQuantity> baseUnits =
null;
1136 private static Dictionary<string, IBaseQuantity> referenceUnits =
null;
1137 private static Dictionary<string, KeyValuePair<Prefix, KeyValuePair<AtomicUnit, int>[]>> compoundUnits =
null;
1138 private static Dictionary<string, PhysicalQuantity> derivedUnits =
null;
1139 private static IUnitCategory[] unitCategories =
null;
1140 private static readonly
object synchObject =
new object();
1144 Types.OnInvalidated += Types_OnInvalidated;
1147 private static void Types_OnInvalidated(
object Sender, EventArgs e)
1152 referenceUnits =
null;
1153 compoundUnits =
null;
1154 derivedUnits =
null;
1155 unitCategories =
null;
1156 categoryPerUnit.Clear();
1166 internal static bool TryGetCompoundUnit(
string Name, out KeyValuePair<
Prefix, KeyValuePair<AtomicUnit, int>[]>
Factors)
1170 if (compoundUnits is
null)
1173 return compoundUnits.TryGetValue(Name, out
Factors);
1182 internal static bool ContainsDerivedOrBaseUnit(
string Name)
1186 if (baseUnits is
null)
1189 return baseUnits.ContainsKey(Name) || derivedUnits.ContainsKey(Name);
1203 return TryConvert(From, FromUnit, 0, ToUnit, out To, out _);
1216 public static bool TryConvert(
double From,
Unit FromUnit,
byte FromNrDec,
Unit ToUnit, out
double To, out
byte ToNrDec)
1220 if (FromUnit.
Equals(ToUnit,
false))
1223 ToNrDec = FromNrDec;
1225 if (FromUnit.prefix != ToUnit.prefix)
1230 if (ExponentDiff != 0)
1232 To *= Math.Pow(10, ExponentDiff);
1233 ToNrDec2 = ToNrDec - ExponentDiff;
1236 else if (ToNrDec2 > 255)
1239 ToNrDec = (byte)ToNrDec2;
1246 double NrDec = FromNrDec;
1251 ToNrDec2 = (int)Math.Round(NrDec);
1253 Unit Div =
Divide(FromUnit, ToUnit, out
int Exponent);
1257 To *= Math.Pow(10, Exponent);
1258 ToNrDec2 -= Exponent;
1263 else if (ToNrDec2 > 255)
1266 ToNrDec = (byte)ToNrDec2;
1283 if (categoryPerUnit.TryGetValue(s, out Category))
1284 return !(Category is
null);
1286 if (unitCategories is
null)
1288 List<IUnitCategory> Categories =
new List<IUnitCategory>();
1300 catch (Exception ex)
1306 Categories.Add(Category);
1309 unitCategories = Categories.ToArray();
1319 Category = Category2;
1326 categoryPerUnit[s] = Category;
1329 return !(Category is
null);
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Static class that dynamically manages types and interfaces available in the runtime environment.
static object[] NoParameters
Contains an empty array of parameter values.
static Type[] GetTypesImplementingInterface(string InterfaceFullName)
Gets all types implementing a given interface.
static ConstructorInfo GetDefaultConstructor(Type Type)
Gets the default constructor of a type, if one exists.
Class managing a script expression.
Represents an atomic unit.
Static class managing units.
static Prefix ExponentToPrefix(int Exponent, out int ResidueExponent)
Converts an exponent to a prefix.
static int PrefixToExponent(Prefix Prefix)
Conerts a prefix to an exponent.
static string ToString(Prefix Prefix)
Converts a prefix to its string representation.
static bool TryConvert(double From, Unit FromUnit, byte FromNrDec, Unit ToUnit, out double To, out byte ToNrDec)
Tries to convert a magnitude in one unit to a magnitude in another.
Unit(Prefix Prefix, params AtomicUnit[] AtomicUnits)
Represents a unit.
static bool TryConvert(double From, Unit FromUnit, Unit ToUnit, out double To)
Tries to convert a magnitude in one unit to a magnitude in another.
Unit FromReferenceUnits(ref double Magnitude, ref double NrDecimals)
Converts the unit to a series of reference unit factors. (Unrecognized units will be assumed to be re...
static Unit Divide(Unit Left, Unit Right, out int ResidueExponent)
Divides the right unit from the left unit: Left /Right .
Unit ToReferenceUnits(ref double Magnitude, ref double NrDecimals)
Converts the unit to a series of reference unit factors. (Unrecognized units will be assumed to be re...
override string ToString()
Unit(Prefix Prefix, params KeyValuePair< AtomicUnit, int >[] Factors)
Represents a unit.
static Unit Parse(string UnitString)
Parses a unit string.
Unit(params string[] AtomicUnits)
Represents a unit.
bool IsEmpty
If the unit is empty. (A unit of only a prefix, but no factors, is not empty.)
Unit(Prefix Prefix, params KeyValuePair< string, int >[] Factors)
Represents a unit.
Unit Invert(out int ResidueExponent)
Inverts the unit.
Unit(Prefix Prefix, params string[] AtomicUnits)
Represents a unit.
override bool Equals(object obj)
bool HasFactors
If the unit has any factors.
bool Equals(Unit Unit2, bool CheckPrefix)
Checks if the unit is equal to another
static readonly Unit Empty
Empty unit.
Unit FromReferenceUnits(ref double Magnitude)
Converts the unit to a series of reference unit factors. (Unrecognized units will be assumed to be re...
string ToString(bool IncludePrefix)
Converts the unit to a string.
static Unit Multiply(Unit Left, Unit Right, out int ResidueExponent)
Multiplies two units with each other.
override int GetHashCode()
Unit ToReferenceUnits(ref double Magnitude)
Converts the unit to a series of reference unit factors. (Unrecognized units will be assumed to be re...
ICollection< KeyValuePair< AtomicUnit, int > > Factors
Sequence of atomic unit factors, and their corresponding exponents.
Unit(Prefix Prefix, ICollection< KeyValuePair< AtomicUnit, int > > Factors)
Represents a unit.
static bool TryParse(string UnitString, out Unit Unit)
Tries to parse a string into a unit.
static bool TryGetCategory(Unit Unit, out IUnitCategory Category)
Tries to get the unit category of a unit.
Unit(params AtomicUnit[] AtomicUnits)
Represents a unit.
Unit ToBaseUnits(ref double Magnitude)
Converts the unit to a series of base unit factors. (Unrecognized units will be assumed to be base un...
Prefix Prefix
Associated prefix.
Interface for physical base quantities
string[] BaseUnits
Base Units supported.
AtomicUnit ReferenceUnit
Reference unit of category.
Interface for physical compound quantities
Tuple< string, Prefix, KeyValuePair< AtomicUnit, int >[]>[] CompoundQuantities
Compound quantities. Must only use base quantity units.
Interface for derived quantities
KeyValuePair< string, PhysicalQuantity >[] DerivedUnits
Derived Units supported.
Interface for a category of units.
Unit Reference
Reference unit for category.
Prefix
SI prefixes. http://physics.nist.gov/cuu/Units/prefixes.html