////////////////////////////////////////////////////////////////////// /// <summary>Creates a shipping object given a shipping attribute. /// </summary> /// <exception cref="ArgumentException">If the attribute /// type is not 'shipping' or unknown</exception> /// <exception cref="FormatException">If the attribute contains /// invalid sub-elements or lacks required sub-elements</exception> ////////////////////////////////////////////////////////////////////// public Shipping(GBaseAttribute attribute) { GBaseAttributeType type = attribute.Type; if (type != null && type != GBaseAttributeType.Shipping) { throw new ArgumentException("Expected an attribute of " + "type 'shipping', got an attribute of type '" + type + "'"); } this.country = GetRequiredAttribute(attribute, "country"); this.service = GetRequiredAttribute(attribute, "service"); string priceString = GetRequiredAttribute(attribute, "price"); try { FloatUnit priceUnit = new FloatUnit(priceString); this.price = priceUnit.Value; this.currency = priceUnit.Unit; } catch (FormatException) { this.price = NumberFormat.ToFloat(priceString); this.currency = null; } }
/////////////////////////////////////////////////////////////////////// /// <summary>Two FloatUnit are equal if both their value and their /// units are equal. No unit conversion is ever done.</summary> /////////////////////////////////////////////////////////////////////// public override bool Equals(object o) { if (Object.ReferenceEquals(this, o)) { return(true); } if (!(o is FloatUnit)) { return(false); } FloatUnit other = o as FloatUnit; return(other.number == number && other.unit == unit); }
/////////////////////////////////////////////////////////////////////// /// <summary>Adds a new attribute of type floatUnit.</summary> /// <param name="name">attribute name</param> /// <param name="value">attribute value</param> /// <returns>the newly-created GBaseAttribute object</returns> /////////////////////////////////////////////////////////////////////// public GBaseAttribute AddFloatUnitAttribute(string name, FloatUnit value) { return(Add(new GBaseAttribute(name, GBaseAttributeType.FloatUnit, value.ToString()))); }
public void testFloatUnitConversion() { FloatUnit fu = new FloatUnit(1.12f, "km"); Assert.AreEqual(fu, new FloatUnit(fu.ToString())); }
/////////////////////////////////////////////////////////////////////// /// <summary>Adds a new attribute of type floatUnit.</summary> /// <param name="name">attribute name</param> /// <param name="value">attribute value</param> /// <returns>the newly-created GBaseAttribute object</returns> /////////////////////////////////////////////////////////////////////// public GBaseAttribute AddFloatUnitAttribute(string name, FloatUnit value) { return Add(new GBaseAttribute(name, GBaseAttributeType.FloatUnit, value.ToString())); }