TunnelVisionLabs.Net.UriTemplate/UriTemplatePart.cs
/// <summary>
/// Encodes text for inclusion in a URI via an expansion.
/// </summary>
/// <param name="text">The text to encode.</param>
/// <param name="allowReservedSet"><see langword="true"/> to allow <c>reserved</c> characters to pass through without percent-encoding; otherwise, <see langword="false"/> to percent-encode these characters.</param>
/// <returns>The encoded text for inclusion in a URI.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="text"/> is <see langword="null"/>.</exception>
Encodes text for inclusion in a URI via an expansion.
Encodes text for inclusion in a URI via an expansion .
protected static string EncodeReservedCharacters(string text, bool allowReservedSet)
        {
            if (text == null)
                throw new ArgumentNullException("text");
            StringBuilder builder = new StringBuilder();
            byte[] encoded = Encoding.UTF8.GetBytes(text);
            foreach (byte b in encoded)
            {
                bool escape = !IsUnreserved(b);
                if (escape && allowReservedSet && IsReserved(b))
                    escape = false;
                if (escape)
                    builder.Append('%').Append(b.ToString("X2"));
                else
                    builder.Append((char)b);
            }
            return builder.ToString();
        }
protected static string EncodeReservedCharacters ( string text , bool allowReservedSet ) { if ( text == null ) throw new ArgumentNullException ( " " ) ; StringBuilder builder = new StringBuilder ( ) ; byte [ ] encoded = Encoding . UTF8 . GetBytes ( text ) ; foreach ( byte b in encoded ) { bool escape = ! IsUnreserved ( b ) ; if ( escape && allowReservedSet && IsReserved ( b ) ) escape = false ; if ( escape ) builder . Append ( ' ' ) . Append ( b . ToString ( " " ) ) ; else builder . Append ( ( char ) b ) ; } return builder . ToString ( ) ; }
Encodes text for inclusion in a URI via an expansion.
Encodes text for inclusion in a URI via an expansion .
The encoded text for inclusion in a URI.
The encoded text for inclusion in a URI .
If  is .
If is .
text
string
The text to encode.
The text to encode .
allowReservedSet
bool
to allow reserved to percent-encode these characters.
to allow reserved to percent - encode these characters .