Ejemplo n.º 1
0
 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));
 }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
 private Measure(SerializationInfo info, StreamingContext context)
 {
     _Unit           = UnitOfMeasure.GetUnitByName(info.GetString("Unit"));
     normalizedValue = info.GetDouble("Value") * _Unit.ConversionFactor;
 }