/// <summary>
        /// Reads the specified node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="types">The types.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override object Read(XmlNode node, NetReflectorTypeTable types)
        {
            if (node == null)
            {
                // NetReflector should do this check, but doesn't
                if (this.Attribute.Required)
                {
                    throw new NetReflectorItemRequiredException(Attribute.Name + " is required");
                }
                else
                {
                    return(null);
                }
            }

            Timeout      timeout = Timeout.DefaultTimeout;
            XmlAttribute a       = node as XmlAttribute;

            if (a != null)
            {
                try
                {
                    timeout = new Timeout(Int32.Parse(a.Value, CultureInfo.CurrentCulture));
                }
                catch (Exception)
                {
                    Log.Warning("Could not parse timeout string. Using default timeout.");
                }
            }
            else
            {
                var e = node as XmlElement;
                if (e != null)
                {
                    try
                    {
                        TimeUnits units       = TimeUnits.MILLIS;
                        string    unitsString = e.GetAttribute("units");
                        if (unitsString != null && !(unitsString != null && unitsString.Length == 0))
                        {
                            units = TimeUnits.Parse(unitsString);
                        }
                        timeout = new Timeout(Int32.Parse(e.InnerText, CultureInfo.CurrentCulture), units);
                    }
                    catch (Exception)
                    {
                        Log.Warning("Could not parse timeout string. Using default timeout.");
                    }
                }
            }
            return(timeout);
        }
Exemplo n.º 2
0
        public override object Read(XmlNode node, NetReflectorTypeTable types)
        {
            Timeout timeout = Timeout.DefaultTimeout;

            if (node is XmlAttribute)
            {
                XmlAttribute a = (XmlAttribute)node;
                try
                {
                    timeout = new Timeout(Int32.Parse(a.Value));
                }
                catch (Exception)
                {
                    Log.Warning("Could not parse timeout string. Using default timeout.");
                }
            }
            else if (node is XmlElement)
            {
                XmlElement e = (XmlElement)node;
                try
                {
                    TimeUnits units       = TimeUnits.MILLIS;
                    string    unitsString = e.GetAttribute("units");
                    if (unitsString != null && unitsString != "")
                    {
                        units = TimeUnits.Parse(unitsString);
                    }
                    timeout = new Timeout(Int32.Parse(e.InnerText), units);
                }
                catch (Exception)
                {
                    Log.Warning("Could not parse timeout string. Using default timeout.");
                }
            }
            return(timeout);
        }