示例#1
0
        /// <summary>
        /// Decodes an HTML-encoded string and returns the decoded string.
        /// </summary>
        /// <param name="s">The HTML string to decode. </param>
        /// <returns>The decoded text.</returns>
        public static string HtmlDecode(string s)
        {
#if NET_4_0
            if (s == null)
            {
                return(null);
            }

            using (var sw = new StringWriter()) {
                HttpEncoderFromMono.Current.HtmlDecode(s, sw);
                return(sw.ToString());
            }
#else
            return(HttpEncoderFromMono.HtmlDecode(s));
#endif
        }
示例#2
0
        /// <summary>
        /// Decodes an HTML-encoded string and sends the resulting output to a TextWriter output stream.
        /// </summary>
        /// <param name="s">The HTML string to decode</param>
        /// <param name="output">The TextWriter output stream containing the decoded string. </param>
        public static void HtmlDecode(string s, TextWriter output)
        {
            if (output == null)
            {
#if NET_4_0
                throw new ArgumentNullException("output");
#else
                throw new NullReferenceException(".NET emulation");
#endif
            }

            if (!String.IsNullOrEmpty(s))
            {
#if NET_4_0
                HttpEncoderFromMono.Current.HtmlDecode(s, output);
#else
                output.Write(HttpEncoderFromMono.HtmlDecode(s));
#endif
            }
        }