System.Security.SecurityElement.GetEscapeSequence C# (CSharp) Method

GetEscapeSequence() private static method

private static GetEscapeSequence ( char c ) : string
c char
return string
        private static string GetEscapeSequence(char c)
        {
            int iMax = s_escapeStringPairs.Length;
            Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");

            for (int i = 0; i < iMax; i += 2)
            {
                string strEscSeq = s_escapeStringPairs[i];
                string strEscValue = s_escapeStringPairs[i + 1];

                if (strEscSeq[0] == c)
                    return strEscValue;
            }

            Debug.Fail("Unable to find escape sequence for this character");
            return c.ToString();
        }

Usage Example

Beispiel #1
0
        /// <summary>Replaces invalid XML characters in a string with their valid XML equivalent.</summary>
        /// <returns>The input string with invalid characters replaced.</returns>
        /// <param name="str">The string within which to escape invalid characters. </param>
        public static string Escape(string str)
        {
            if (str == null)
            {
                return(null);
            }
            StringBuilder stringBuilder = null;
            int           length        = str.Length;
            int           num           = 0;

            while (true)
            {
                int num2 = str.IndexOfAny(SecurityElement.s_escapeChars, num);
                if (num2 == -1)
                {
                    break;
                }
                if (stringBuilder == null)
                {
                    stringBuilder = new StringBuilder();
                }
                stringBuilder.Append(str, num, num2 - num);
                stringBuilder.Append(SecurityElement.GetEscapeSequence(str[num2]));
                num = num2 + 1;
            }
            if (stringBuilder == null)
            {
                return(str);
            }
            stringBuilder.Append(str, num, length - num);
            return(stringBuilder.ToString());
        }
All Usage Examples Of System.Security.SecurityElement::GetEscapeSequence