/// <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) });
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; } }
/// <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); } }
/// <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); } }
public float ChangeUnit(VoltageUnit newUnit) { return(value * Ratio[(int)unit] / Ratio[(int)newUnit]); }
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; }
/// <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 }
/// <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) { }
/// <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) }) { }
/// <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) }) { }
private VoltageJsonConverter(VoltageUnit unit) { this.unit = unit; }
protected static string CreateSuffix(SymbolFormat format, VoltageUnit unit) { return default(Voltage).ToString(unit, format).Trim('0'); }