Esempio n. 1
0
 /// <summary>
 /// Converts the <see cref="Voltage"/> to the specified <paramref name="targetUnit"/>.
 /// </summary>
 /// <param name="targetUnit">Target units.</param>
 /// <returns><see cref="Voltage"/> converted to <paramref name="targetUnit"/>.</returns>
 public double ConvertTo(VoltageUnit targetUnit)
 {
     return(targetUnit switch
     {
         VoltageUnit.Volts => m_value,
         VoltageUnit.Abvolts => ToAbvolts(),
         VoltageUnit.Statvolts => ToStatvolts(),
         _ => throw new ArgumentOutOfRangeException(nameof(targetUnit), targetUnit, null)
     });
Esempio n. 2
0
 public Voltage(string value, string unit)
 {
     try
     {
         this.value = float.Parse(value);
         this.unit  = (VoltageUnit)Enum.Parse(typeof(VoltageUnit), unit);
     }
     catch
     {
         this.value = defaultValue;
         this.unit  = defaultUnit;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Converts the <paramref name="value"/> in the specified <paramref name="sourceUnit"/> to a new <see cref="Voltage"/> in volts.
        /// </summary>
        /// <param name="value">Source value.</param>
        /// <param name="sourceUnit">Source value units.</param>
        /// <returns>New <see cref="Voltage"/> from the specified <paramref name="value"/> in <paramref name="sourceUnit"/>.</returns>
        public static Voltage ConvertFrom(double value, VoltageUnit sourceUnit)
        {
            switch (sourceUnit)
            {
            case VoltageUnit.Volts:
                return(value);

            case VoltageUnit.Abvolts:
                return(FromAbvolts(value));

            case VoltageUnit.Statvolts:
                return(FromStatvolts(value));

            default:
                throw new ArgumentOutOfRangeException(nameof(sourceUnit), sourceUnit, null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Converts the <see cref="Voltage"/> to the specified <paramref name="targetUnit"/>.
        /// </summary>
        /// <param name="targetUnit">Target units.</param>
        /// <returns><see cref="Voltage"/> converted to <paramref name="targetUnit"/>.</returns>
        public double ConvertTo(VoltageUnit targetUnit)
        {
            switch (targetUnit)
            {
            case VoltageUnit.Volts:
                return(m_value);

            case VoltageUnit.Abvolts:
                return(ToAbvolts());

            case VoltageUnit.Statvolts:
                return(ToStatvolts());

            default:
                throw new ArgumentOutOfRangeException(nameof(targetUnit), targetUnit, null);
            }
        }
Esempio n. 5
0
 public float ChangeUnit(VoltageUnit newUnit)
 {
     return(value * Ratio[(int)unit] / Ratio[(int)newUnit]);
 }
Esempio n. 6
0
 public Voltage(float value, VoltageUnit unit)
 {
     this.value = value;
     this.unit  = unit;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="Gu.Units.Wpf.VoltageConverter"/>.
 /// </summary>
 /// <param name="unit"><see cref="Gu.Units.VoltageUnit"/>.</param>
 public VoltageConverter(VoltageUnit unit)
 {
     Unit = unit;
 }
Esempio n. 8
0
 /// <summary>
 /// Creates a new instance of a work unit based on voltage and current.
 /// </summary>
 /// <param name="voltageUnit">The unit of the voltage.</param>
 /// <param name="currentUnit">The unit of the current.</param>
 public WorkUnit(VoltageUnit voltageUnit, CurrentUnit currentUnit)
     : base(new UnitCompositeCollection() { new MultipliedByUnit(voltageUnit, 1), new MultipliedByUnit(currentUnit, 1) })
 {
     // Work can also be VA, so public.
 }
 /// <summary>
 /// Creates a new instance of a resistance unit.
 /// </summary>
 /// <param name="voltage">The voltage difference</param>
 /// <param name="current">The electric current.</param>
 public ResistanceUnit(VoltageUnit voltage, CurrentUnit current)
     : base(new UnitCompositeCollection() { new MultipliedByUnit(voltage, 1), new DividedByUnit(current, 1) })
 {
     // resistance is always voltage over current, so public
 }
Esempio n. 10
0
 /// <summary>
 /// Creates a multiple of the base unit.
 /// </summary>
 /// <param name="multiple">The multiple that should be applied to the base unit.</param>
 /// <param name="voltageUnit">The unit for the voltage</param>
 protected VoltageUnit(Multiple multiple, VoltageUnit voltageUnit)
     : base(multiple, voltageUnit)
 {
 }
Esempio n. 11
0
 /// <summary>
 /// Creates a new instance of a electric power.
 /// </summary>
 /// <param name="voltage">The unit for the voltage</param>
 /// <param name="current">The unit for the current</param>
 protected PowerUnit(VoltageUnit voltage, CurrentUnit current)
     : base(new UnitCompositeCollection() { new MultipliedByUnit(voltage, 1), new MultipliedByUnit(current, 1) })
 {
 }
Esempio n. 12
0
 /// <summary>
 /// Creates a new instance of capacitance based on electric charge and voltage.
 /// </summary>
 /// <param name="chargeUnit">The unit of the electric charge.</param>
 /// <param name="voltageUnit">The unit of the voltage.</param>
 public CapacitanceUnit(ElectricChargeUnit chargeUnit, VoltageUnit voltageUnit)
     : base(new UnitCompositeCollection() { new MultipliedByUnit(chargeUnit, 1), new DividedByUnit(voltageUnit, 1) })
 {
 }
Esempio n. 13
0
 private VoltageJsonConverter(VoltageUnit unit)
 {
     this.unit = unit;
 }
 protected static string CreateSuffix(SymbolFormat format, VoltageUnit unit)
 {
     return default(Voltage).ToString(unit, format).Trim('0');
 }