public static UnitValue Convert(UnitValue fromValue, String targetUnit) { var cu = new CombinedUnit(fromValue.Unit); var conversions = cu.ConvertTo(targetUnit); var re = fromValue.Re; foreach (var conversation in conversions) { re = conversation(re); } return new UnitValue(cu.Factor * re, cu.Unit); }
public UnitValue Function(UnitValue value, StringValue to) { return(Convert(value, to.Value)); }
/// <summary> /// Creates a new unit value. /// </summary> /// <param name="value">The unit to copy.</param> public UnitValue(UnitValue value) : this(value.Re, value.Unit) { }
/// <summary> /// Transforms a binary representation into a new instance. /// </summary> /// <param name="content">The binary data.</param> /// <returns>The new instance.</returns> public override Value Deserialize(Byte[] content) { var unit = new UnitValue(); unit.Re = BitConverter.ToDouble(content, 0); unit.Im = BitConverter.ToDouble(content, 8); var str = new char[BitConverter.ToInt32(content, 16)]; for (var i = 0; i < str.Length; i++) { str[i] = BitConverter.ToChar(content, 20 + 2 * i); } unit._unit = new String(str); return unit; }
public UnitValue Function(UnitValue value, StringValue to) { return Convert(value, to.Value); }