DynamoVisualProgramming.ZeroTouchLibrary by Autodesk

<PackageReference Include="DynamoVisualProgramming.ZeroTouchLibrary" Version="1.3.4.6116" />

 Insolation

using Autodesk.DesignScript.Runtime; using System; using System.Collections.Generic; using System.Globalization; namespace DynamoUnits { [IsVisibleInDynamoLibrary(false)] public class Insolation : SIUnit, IComparable, IEquatable<Insolation> { private const double WHM2_TO_KWHM2 = 0.001; private const double WHM2_TO_BT_UFT2 = 0.317; public const string WATT_HOURS_PER_SQUARE_METER = "Wh/m²"; public const string KILLOWATT_HOURS_PER_SQUARE_METER = "kWh/m²"; public const string BTU_PER_SQUARE_FOOT = "BTU/ft²"; private InsolationUnit _insolationUnit; [IsVisibleInDynamoLibrary(false)] public InsolationUnit InsolationUnit { get { return _insolationUnit; } set { _insolationUnit = value; } } [IsVisibleInDynamoLibrary(false)] public double UiInsolationConversion { get { switch (_insolationUnit) { case InsolationUnit.WattHoursPerMeterSquared: return 1; case InsolationUnit.KilowattHoursPerMeterSquared: return ToKwhMeter2; case InsolationUnit.BTUPerFootSquared: return ToBTUFoot2; default: return 1; } } } [IsVisibleInDynamoLibrary(false)] public override double UnitValue { get { return _value * UiInsolationConversion; } } public static double ToKwhMeter2 => 0.001; public static double ToBTUFoot2 => 0.317; public new static Dictionary<string, double> Conversions => new Dictionary<string, double> { { "Wh/m²", 1 }, { "kWh/m²", 0.001 }, { "BTU/ft²", 0.317 } }; public static Insolation FromDouble(double value) { return new Insolation(value); } internal Insolation(double value) : base(value) { } public override void SetValueFromString(string value) { throw new NotImplementedException(); } public override SIUnit Add(SIUnit x) { if (x is Insolation) return new Insolation(_value + x.Value); throw new UnitsException(GetType(), x.GetType()); } public override SIUnit Add(double x) { return new Insolation(_value + x); } public override SIUnit Subtract(SIUnit x) { if (x is Insolation) return new Insolation(_value - x.Value); throw new UnitsException(GetType(), x.GetType()); } public override SIUnit Subtract(double x) { return new Insolation(_value - x); } public override SIUnit Multiply(SIUnit x) { throw new UnitsException(GetType(), x.GetType()); } public override SIUnit Multiply(double x) { return new Insolation(_value * x); } public override dynamic Divide(SIUnit x) { throw new UnitsException(GetType(), x.GetType()); } public override SIUnit Divide(double x) { return new Insolation(_value / x); } public override SIUnit Modulo(SIUnit x) { if (x is Insolation) return new Insolation(_value % x.Value); throw new UnitsException(GetType(), x.GetType()); } public override SIUnit Modulo(double x) { return new Insolation(_value % x); } public override SIUnit Round() { return new Insolation(Math.Round(_value)); } public override SIUnit Ceiling() { return new Insolation(Math.Ceiling(_value)); } public override SIUnit Floor() { return new Insolation(Math.Floor(_value)); } public override double ConvertToHostUnits() { return base.Value; } public int CompareTo(object obj) { if (obj == null) return 1; Insolation insolation = obj as Insolation; if (insolation != null) return _value.CompareTo(insolation.Value); throw new ArgumentException("Object is not an Insolation."); } public bool Equals(Insolation other) { if (other == null) return false; return Math.Abs(other.Value - _value) < BaseUnit.Epsilon; } [IsVisibleInDynamoLibrary(false)] public override string ToString() { double num; switch (InsolationUnit) { case InsolationUnit.WattHoursPerMeterSquared: return _value.ToString(BaseUnit.NumberFormat, CultureInfo.InvariantCulture) + "Wh/m²"; case InsolationUnit.KilowattHoursPerMeterSquared: num = _value * ToKwhMeter2; return num.ToString(BaseUnit.NumberFormat, CultureInfo.InvariantCulture) + "kWh/m²"; case InsolationUnit.BTUPerFootSquared: num = _value * ToBTUFoot2; return num.ToString(BaseUnit.NumberFormat, CultureInfo.InvariantCulture) + "BTU/ft²"; default: return _value.ToString(BaseUnit.NumberFormat, CultureInfo.InvariantCulture) + "Wh/m²"; } } } }