Пример #1
0
        /// <summary>
        /// Creates a deep clone of this instance.
        /// </summary>
        /// <returns>The cloned <see cref="NetworkBinding" />.</returns>
        public NetworkBinding Clone()
        {
            var clone = new NetworkBinding();

            clone.host    = this.host;
            clone.address = this.address;
            clone.port    = this.port;

            return(clone);
        }
Пример #2
0
        /// <summary>
        /// Parses the string passed unless the string is <c>null</c> or
        /// the parse failed, in which case the default value
        /// will be returned.
        /// </summary>
        /// <param name="value">The string to be parsed.</param>
        /// <param name="def">The default value.</param>
        /// <returns>The parsed value on success, the default value on failure.</returns>
        /// <remarks>
        /// Network bindings are formatted as &lt;dotted-quad&gt;:&lt;port&gt; or
        /// &lt;host&gt;:&lt;port&gt;
        /// </remarks>
        public static NetworkBinding Parse(string value, NetworkBinding def)
        {
            if (value == null)
            {
                return(def);
            }

            try
            {
                return(NetworkBinding.Parse(value));
            }
            catch
            {
                return(def);
            }
        }
Пример #3
0
        /// <summary>
        /// Attempts to parse a <see cref="NetworkBinding" />.
        /// </summary>
        /// <param name="text">The binding string to be parsed.</param>
        /// <param name="binding">Returns as the parsed binding.</param>
        /// <returns><c>true</c> if the operation was successful.</returns>
        public static bool TryParse(string text, out NetworkBinding binding)
        {
            // $todo(jeff.lill):
            //
            // Implement this without having to catch exceptions
            // to improve performance

            binding = null;

            try
            {
                binding = Parse(text);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #4
0
 /// <summary>
 /// Parses the string passed unless the string is <c>null</c> or
 /// the parse failed, in which case the default value
 /// will be returned.
 /// </summary>
 /// <param name="columnName">The column name.</param>
 /// <param name="def">The default value.</param>
 /// <returns>The parsed value on success, the default value on failure.</returns>
 /// <remarks>
 /// Network bindings are formatted as &lt;dotted-quad&gt;:&lt;port&gt; or
 /// &lt;host&gt;:&lt;port&gt;
 /// </remarks>
 public NetworkBinding Parse(string columnName, NetworkBinding def)
 {
     return(Serialize.Parse(GetColumn(columnName), def));
 }
Пример #5
0
 /// <summary>
 /// Serializes the value passed into a string.
 /// </summary>
 /// <param name="v">The value</param>
 /// <returns>The output string.</returns>
 /// <remarks>
 /// Network bindings are formatted as &lt;dotted-quad&gt;:&lt;port&gt; or
 /// &lt;host&gt;:&lt;port&gt;
 /// </remarks>
 public static string ToString(NetworkBinding v)
 {
     return(v.ToString());
 }
Пример #6
0
        /// <summary>
        /// Returns the named value if it exists in the user's profile otherwise
        /// returns a specified default value.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="def">The default value.</param>
        /// <returns>The named value from the user's profile if it is present, the default value otherwise.</returns>
        public NetworkBinding Get(string name, NetworkBinding def)
        {
            var value = this[name];

            return(value != null?Config.ParseValue(value, def) : def);
        }
Пример #7
0
 /// <summary>
 /// Sets a name/value pair in the user's profile.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 public void Set(string name, NetworkBinding value)
 {
     Set(name, Serialize.ToString(value));
 }
Пример #8
0
        /// <summary>
        /// Searches a <see cref="XContainer" /> for the first <see cref="XElement" /> instance with the specified
        /// specified <see cref="XName" /> and then parses and returns its value as a
        /// an <see cref="NetworkBinding" />.
        /// </summary>
        /// <param name="container">The <see cref="XContainer" /></param>
        /// <param name="name">The attribute <see cref="XName" />.</param>
        /// <param name="def">The default value.</param>
        /// <returns>The parsed value on success, the default value on failure.</returns>
        /// <remarks>
        /// Network bindings are formatted as &lt;dotted-quad&gt;:&lt;port&gt; or
        /// &lt;host&gt;:&lt;port&gt;
        /// </remarks>
        public static NetworkBinding ParseElement(this XContainer container, XName name, NetworkBinding def)
        {
            var element = container.Element(name);
            var value   = element != null ? element.Value : null;

            return(Serialize.Parse(value, def));
        }
Пример #9
0
        /// <summary>
        /// Searches a <see cref="XElement" /> for the first attribute instance with the
        /// specified <see cref="XName" /> and then parses and returns its value as a
        /// an <see cref="NetworkBinding" />.
        /// </summary>
        /// <param name="element">The <see cref="XElement" /></param>
        /// <param name="name">The attribute <see cref="XName" />.</param>
        /// <param name="def">The default value.</param>
        /// <returns>The parsed value on success, the default value on failure.</returns>
        /// <remarks>
        /// Network bindings are formatted as &lt;dotted-quad&gt;:&lt;port&gt; or
        /// &lt;host&gt;:&lt;port&gt;
        /// </remarks>
        public static NetworkBinding ParseAttribute(this XElement element, XName name, NetworkBinding def)
        {
            var attribute = element.Attribute(name);
            var value     = attribute != null ? attribute.Value : null;

            return(Serialize.Parse(value, def));
        }
Пример #10
0
 /// <summary>
 /// Sets the value of a named table column in the current row.
 /// </summary>
 /// <param name="columnName">The column name.</param>
 /// <param name="value">The column value.</param>
 /// <remarks>
 /// <note>
 /// This method will do nothing if the <paramref name="columnName" />
 /// passed does not map to a table column.
 /// </note>
 /// </remarks>
 public void Set(string columnName, NetworkBinding value)
 {
     Set(columnName, value != null ? Serialize.ToString(value) : string.Empty);
 }