public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string unitStr) { return(UnitOfMeasure.GetUnitByName(unitStr)); } return(base.ConvertFrom(context, culture, value)); }
public void ReadXml(XmlReader reader) { reader.MoveToContent(); var value = double.Parse(reader.GetAttribute("Value")); _Unit = UnitOfMeasure.GetUnitByName(reader.GetAttribute("Unit")); if (_Unit == null) { normalizedValue = value; } else { normalizedValue = _Unit.ConversionFactor * value; } }
private Measure(SerializationInfo info, StreamingContext context) { _Unit = UnitOfMeasure.GetUnitByName(info.GetString("Unit")); normalizedValue = info.GetDouble("Value") * _Unit.ConversionFactor; }