HtmlAttributeEncode() public static method

Encode an HTML attribute value.
Encodes an HTML attribute value.
/// is null. /// /// and do not specify /// a valid range in the value. /// /// is not a valid quote character. ///
public static HtmlAttributeEncode ( char value, int startIndex, int count, char quote = '"' ) : string
value char The attribute value to encode.
startIndex int The starting index of the attribute value.
count int The number of characters in the attribute value.
quote char The character to use for quoting the attribute value.
return string
Exemplo n.º 1
0
        /// <summary>
        /// Write the HTML tag to a <see cref="System.IO.TextWriter"/>.
        /// </summary>
        /// <remarks>
        /// Writes the HTML tag to a <see cref="System.IO.TextWriter"/>.
        /// </remarks>
        /// <param name="output">The output.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="output"/> is <c>null</c>.
        /// </exception>
        public override void WriteTo(TextWriter output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            output.Write('<');
            if (IsEndTag)
            {
                output.Write('/');
            }
            output.Write(Name);
            for (int i = 0; i < Attributes.Count; i++)
            {
                output.Write(' ');
                output.Write(Attributes[i].Name);
                if (Attributes[i].Value != null)
                {
                    output.Write('=');
                    HtmlUtils.HtmlAttributeEncode(output, Attributes[i].Value);
                }
            }
            if (IsEmptyElement)
            {
                output.Write('/');
            }
            output.Write('>');
        }
Exemplo n.º 2
0
        void EncodeAttributeValue(string value)
        {
            if (WriterState != HtmlWriterState.Attribute)
            {
                throw new InvalidOperationException("Attribute values can only be written in the Attribute state.");
            }

            html.Write('=');
            HtmlUtils.HtmlAttributeEncode(html, value);
            WriterState = HtmlWriterState.Tag;
        }
Exemplo n.º 3
0
        void EncodeAttributeValue(char[] value, int startIndex, int count)
        {
            if (WriterState != HtmlWriterState.Attribute)
            {
                throw new InvalidOperationException("Attribute values can only be written in the Attribute state.");
            }

            html.Write('=');
            HtmlUtils.HtmlAttributeEncode(html, value, startIndex, count);
            WriterState = HtmlWriterState.Tag;
        }