예제 #1
0
        public static string HtmlEncode(string s)
        {
#if NET_4_0
            if (s == null)
            {
                return(null);
            }

            using (var sw = new StringWriter()) {
                HttpEncoderFromMono.Current.HtmlEncode(s, sw);
                return(sw.ToString());
            }
#else
            return(HttpEncoderFromMono.HtmlEncode(s));
#endif
        }
예제 #2
0
        /// <summary>
        /// HTML-encodes a string and sends the resulting output to a TextWriter output stream.
        /// </summary>
        /// <param name="s">The string to encode. </param>
        /// <param name="output">The TextWriter output stream containing the encoded string. </param>
        public static void HtmlEncode(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.HtmlEncode(s, output);
#else
                output.Write(HttpEncoderFromMono.HtmlEncode(s));
#endif
            }
        }