TunnelVisionLabs.Net.UriTemplate/VariableReference.cs
/// <summary>
/// Parse a variable reference from an RFC 6570 URI Template to a <see cref="VariableReference"/> object.
/// </summary>
/// <param name="variable">The RFC 6570 variable reference to parse.</param>
/// <returns>A <see cref="VariableReference"/> object representing the variable reference.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="variable"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">If <paramref name="variable"/> is empty.</exception>
/// <exception cref="FormatException">If <paramref name="variable"/> is not a valid <c>varspec</c> according to RFC 6570.</exception>
Parse a variable reference from an RFC 6570 URI Template to a  object.
Parse a variable reference from an RFC 6570 URI Template to a object .
internal static VariableReference Parse(string variable)
        {
            if (variable == null)
                throw new ArgumentNullException("reference");
            if (string.IsNullOrEmpty(variable))
                throw new ArgumentException("reference cannot be empty");
            try
            {
                bool explode = variable[variable.Length - 1] == '*';
                if (explode)
                {
                    string name = variable.Substring(0, variable.Length - 1);
                    return new VariableReference(name, true);
                }
                int colon = variable.IndexOf(':');
                if (colon >= 0)
                {
                    string name = variable.Substring(0, colon);
                    int prefix = int.Parse(variable.Substring(colon + 1));
                    return new VariableReference(name, prefix);
                }
                return new VariableReference(variable);
            }
            catch (Exception ex)
            {
                throw new FormatException("The specified varspec is not valid.", ex);
            }
        }
internal static VariableReference Parse ( string variable ) { if ( variable == null ) throw new ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( variable ) ) throw new ArgumentException ( " " ) ; try { bool explode = variable [ variable . Length - 1 ] == ' ' ; if ( explode ) { string name = variable . Substring ( 0 , variable . Length - 1 ) ; return new VariableReference ( name , true ) ; } int colon = variable . IndexOf ( ' ' ) ; if ( colon >= 0 ) { string name = variable . Substring ( 0 , colon ) ; int prefix = int . Parse ( variable . Substring ( colon + 1 ) ) ; return new VariableReference ( name , prefix ) ; } return new VariableReference ( variable ) ; } catch ( Exception ex ) { throw new FormatException ( " " , ex ) ; } }
Parse a variable reference from an RFC 6570 URI Template to a  object.
Parse a variable reference from an RFC 6570 URI Template to a object .
A  object representing the variable reference.
A object representing the variable reference .
If  is .
If is .
If  is empty.
If is empty .
If  is not a valid varspec
If is not a valid varspec
variable
string
The RFC 6570 variable reference to parse.
The RFC 6570 variable reference to parse .