//////////////////////////////////////////////////////////////////////
        /// <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>Extracts location information from an attribute.
 /// </summary>
 /// <exception cref="FormatException">If the attribute contains
 /// invalid sub-elements or lacks required sub-elements</exception>
 //////////////////////////////////////////////////////////////////////
 public Location(GBaseAttribute attribute)
 {
     this.address = attribute.Content;
     if (attribute["latitude"] != null && attribute["longitude"] != null)
     {
         this.latitude       = NumberFormat.ToFloat(attribute["latitude"]);
         this.longitude      = NumberFormat.ToFloat(attribute["longitude"]);
         this.hasCoordinates = true;
     }
 }
        private List <float> GetAttributesAsFloat(string name, GBaseAttributeType type)
        {
            List <float> retval = new List <float>();

            foreach (GBaseAttribute attribute in GetAttributes(name, type))
            {
                String content = attribute.Content;
                if (content != null)
                {
                    retval.Add(NumberFormat.ToFloat(content));
                }
            }
            return(retval);
        }
        private bool ExtractAttributeAsFloat(string name,
                                             out float value,
                                             GBaseAttributeType type)
        {
            String stringValue = GetAttributeAsString(name, type);

            if (stringValue == null)
            {
                value = 0;
                return(false);
            }
            value = NumberFormat.ToFloat(stringValue);
            return(true);
        }
Exemple #5
0
 ///////////////////////////////////////////////////////////////////////
 /// <summary>Extracts the number and unit from a string
 /// of the form: <c>number " " unit</c></summary>
 /// <exception cref="FormatException">Thrown when the string
 /// representation could not be used to generate a valid
 /// FloatUnit.</exception>
 ///////////////////////////////////////////////////////////////////////
 public FloatUnit(String str)
     : base(ExtractUnit(str))
 {
     this.number = NumberFormat.ToFloat(ExtractNumber(str));
 }