TunnelVisionLabs.Net.UriTemplate/UriTemplate.cs
/// <overloads>
/// <summary>
/// Attempts to match a <see cref="Uri"/> to a <see cref="UriTemplate"/>. A successful
/// match operation results in an assignment of values to variables in the URI Template
/// which is capable of producing a <c>candidate</c> URI through the
/// <see cref="O:TunnelVisionLabs.Net.UriTemplate.BindByName"/> operation.
/// </summary>
/// <remarks>
/// <para>There are several limitations in the current implementation of this operation.</para>
///
/// <list type="bullet">
///   <item>
///     If more than one assignment of values to variables exists which is capable of
///     producing the <c>candidate</c> URI through the <see cref="O:TunnelVisionLabs.Net.UriTemplate.BindByName"/>
///     operation, it is unspecified which assignment of values is chosen.
///   </item>
///   <item>
///     Simple string values will always be returned as a <see cref="string"/>.
///     Associative array values will always be returned as an <see cref="IList{T}"/> whose
///     values are of type <see cref="string"/>. Associative map values will always be
///     returned as an <see cref="IDictionary{TKey, TValue}"/> whose keys and values are
///     of type <see cref="string"/>. No other deserialization or coercion of values is
///     performed by this library.
///   </item>
/// </list>
///
/// <para>
/// The matching algorithm prefers to use simple string values for all variables not
/// explicitly listed in <c>arrayVariables</c> and/or <c>mapVariables</c>. Any variable
/// listed in either of these parameters will not be considered for matching as a simple
/// string. If no assignment of values to variables is possible using this choice, one or
/// more variables may be treated as associative arrays and/or maps in order to produce a
/// successful assignment. The exception to this rule is compound template variables
/// (which use the explode modifier); these variables prefer to match as arrays instead
/// of simple strings, even if the result produces an array containing exactly one
/// string. If a variable appears in both <c>arrayVariables</c> and <c>mapVariables</c>
/// and the result successfully matches using both options, it is unspecified which one
/// will be returned.
/// </para>
/// </remarks>
/// <conceptualLink target="7e56a038-ad98-4922-9342-7f68a5b89283"/>
/// </overloads>
/// <summary>
/// Attempts to match a <see cref="Uri"/> to a <see cref="UriTemplate"/>.
/// </summary>
/// <remarks>
/// <para>For detailed information about the behavior of this method, see the remarks in the
/// documentation for the <see cref="O:TunnelVisionLabs.Net.UriTemplate.Match"/> methods.</para>
/// </remarks>
/// <param name="candidate">The <see cref="Uri"/> to match against the template.</param>
/// <param name="requiredVariables">A collection of variables which must be provided during the expansion process for the resulting URI to be valid. The default value is an empty collection.</param>
/// <param name="arrayVariables">A collection of variables to treat as associative arrays when matching a candidate URI to the template. Associative arrays are returned as instances of <see cref="IList{T}"/> whose values are of type <see cref="string"/>. The default value is an empty collection.</param>
/// <param name="mapVariables">A collection of variables to treat as associative maps when matching a candidate URI to the template. Associative maps are returned as instances of <see cref="IDictionary{TKey, TValue}"/> whose keys and values are of type <see cref="string"/>. The default value is an empty collection.</param>
/// <returns>A <see cref="UriTemplateMatch"/> object containing the results of the match operation, or <see langword="null"/> if the match failed.</returns>
/// <exception cref="ArgumentNullException">
/// <para>If <paramref name="candidate"/> is <see langword="null"/>.</para>
/// <para>-or-</para>
/// <para>If <paramref name="requiredVariables"/> is <see langword="null"/>.</para>
/// <para>-or-</para>
/// <para>If <paramref name="arrayVariables"/> is <see langword="null"/>.</para>
/// <para>-or-</para>
/// <para>If <paramref name="mapVariables"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentException">
/// <para>If <paramref name="requiredVariables"/> contains a <see langword="null"/> or empty value.</para>
/// <para>-or-</para>
/// <para>If <paramref name="arrayVariables"/> contains a <see langword="null"/> or empty value.</para>
/// <para>-or-</para>
/// <para>If <paramref name="mapVariables"/> contains a <see langword="null"/> or empty value.</para>
/// </exception>
/// <conceptualLink target="7e56a038-ad98-4922-9342-7f68a5b89283"/>
Attempts to match a  to a .
Attempts to match a to a .
public UriTemplateMatch Match(Uri candidate, ICollection<string> requiredVariables, ICollection<string> arrayVariables, ICollection<string> mapVariables)
        {
            if (candidate == null)
                throw new ArgumentNullException("candidate");
            if (requiredVariables == null)
                throw new ArgumentNullException("requiredVariables");
            if (arrayVariables == null)
                throw new ArgumentNullException("arrayVariables");
            if (mapVariables == null)
                throw new ArgumentNullException("mapVariables");
            StringBuilder pattern = new StringBuilder();
            pattern.Append('^');
            for (int i = 0; i < _parts.Length; i++)
            {
                string group = "part" + i;
                _parts[i].BuildPattern(pattern, group, requiredVariables, arrayVariables, mapVariables);
            }
            pattern.Append('$');
            Match match = Regex.Match(candidate.OriginalString, pattern.ToString());
            if (match == null || !match.Success)
                return null;
            List<KeyValuePair<VariableReference, object>> bindings = new List<KeyValuePair<VariableReference, object>>();
            for (int i = 0; i < _parts.Length; i++)
            {
                Group group = match.Groups["part" + i];
                if (!group.Success)
                    return null;
                KeyValuePair<VariableReference, object>[] binding = _parts[i].Match(group.Value, requiredVariables, arrayVariables, mapVariables);
                if (binding == null)
                    return null;
                bindings.AddRange(binding);
            }
            return new UriTemplateMatch(this, bindings);
        }
public UriTemplateMatch Match ( Uri candidate , ICollection < string > requiredVariables , ICollection < string > arrayVariables , ICollection < string > mapVariables ) { if ( candidate == null ) throw new ArgumentNullException ( " " ) ; if ( requiredVariables == null ) throw new ArgumentNullException ( " " ) ; if ( arrayVariables == null ) throw new ArgumentNullException ( " " ) ; if ( mapVariables == null ) throw new ArgumentNullException ( " " ) ; StringBuilder pattern = new StringBuilder ( ) ; pattern . Append ( ' ' ) ; for ( int i = 0 ; i < _parts . Length ; i ++ ) { string group = " " + i ; _parts [ i ] . BuildPattern ( pattern , group , requiredVariables , arrayVariables , mapVariables ) ; } pattern . Append ( ' ' ) ; Match match = Regex . Match ( candidate . OriginalString , pattern . ToString ( ) ) ; if ( match == null || ! match . Success ) return null ; List < KeyValuePair < VariableReference , object > > bindings = new List < KeyValuePair < VariableReference , object > > ( ) ; for ( int i = 0 ; i < _parts . Length ; i ++ ) { Group group = match . Groups [ " " + i ] ; if ( ! group . Success ) return null ; KeyValuePair < VariableReference , object > [ ] binding = _parts [ i ] . Match ( group . Value , requiredVariables , arrayVariables , mapVariables ) ; if ( binding == null ) return null ; bindings . AddRange ( binding ) ; } return new UriTemplateMatch ( this , bindings ) ; }
Attempts to match a  to a .
Attempts to match a to a .
A  object containing the results of the match operation, or  if the match failed.
A object containing the results of the match operation or if the match failed .
None
If  contains a  or empty value.-or-If  contains a  or empty value.-or-If  contains a  or empty value.
If contains a or empty value . - or - If contains a or empty value . - or - If contains a or empty value .
candidate
Uri
The  to match against the template.
The to match against the template .
requiredVariables
ICollection<string>
A collection of variables which must be provided during the expansion process for the resulting URI to be valid. The default value is an empty collection.
A collection of variables which must be provided during the expansion process for the resulting URI to be valid . The default value is an empty collection .
arrayVariables
ICollection<string>
A collection of variables to treat as associative arrays when matching a candidate URI to the template. Associative arrays are returned as instances of  whose values are of type . The default value is an empty collection.
A collection of variables to treat as associative arrays when matching a candidate URI to the template . Associative arrays are returned as instances of whose values are of type . The default value is an empty collection .
mapVariables
ICollection<string>
A collection of variables to treat as associative maps when matching a candidate URI to the template. Associative maps are returned as instances of  whose keys and values are of type . The default value is an empty collection.
A collection of variables to treat as associative maps when matching a candidate URI to the template . Associative maps are returned as instances of whose keys and values are of type . The default value is an empty collection .
overloads
Attempts to match a  to a . A successful
match operation results in an assignment of values to variables in the URI Template
which is capable of producing a candidate operation.
There are several limitations in the current implementation of this operation.



If more than one assignment of values to variables exists which is capable of
producing the
candidate
operation, it is unspecified which assignment of values is chosen.

Simple string values will always be returned as a .
Associative array values will always be returned as an  whose
values are of type . Associative map values will always be
returned as an  whose keys and values are
of type . No other deserialization or coercion of values is
performed by this library.

The matching algorithm prefers to use simple string values for all variables not
explicitly listed in arrayVariablesmapVariablesarrayVariablesmapVariables
Attempts to match a to a . A successful match operation results in an assignment of values to variables in the URI Template which is capable of producing a candidate operation . There are several limitations in the current implementation of this operation . If more than one assignment of values to variables exists which is capable of producing the candidate operation it is unspecified which assignment of values is chosen . Simple string values will always be returned as a . Associative array values will always be returned as an whose values are of type . Associative map values will always be returned as an whose keys and values are of type . No other deserialization or coercion of values is performed by this library . The matching algorithm prefers to use simple string values for all variables not explicitly listed in arrayVariablesmapVariablesarrayVariablesmapVariables
remarks
For detailed information about the behavior of this method, see the remarks in the
documentation for the  methods.
For detailed information about the behavior of this method see the remarks in the documentation for the methods .
conceptualLink
None