Example #1
0
        private static bool ParseElementForObjectCreation(SecurityElement el, string requiredNamespace, out string className, out int classNameStart, out int classNameLength)
        {
            className       = (string)null;
            classNameStart  = 0;
            classNameLength = 0;
            int    length     = requiredNamespace.Length;
            string className1 = el.Attribute("class");

            if (className1 == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NoClass"));
            }
            if (className1.IndexOf('\'') >= 0)
            {
                className1 = className1.Replace('\'', '"');
            }
            if (!PermissionToken.IsMscorlibClassName(className1))
            {
                return(false);
            }
            int num1 = className1.IndexOf(',');
            int num2 = num1 != -1 ? num1 : className1.Length;

            if (num2 <= length || !className1.StartsWith(requiredNamespace, StringComparison.Ordinal))
            {
                return(false);
            }
            className       = className1;
            classNameLength = num2 - length;
            classNameStart  = length;
            return(true);
        }
        private static bool ParseElementForObjectCreation(SecurityElement el, string requiredNamespace, out string className, out int classNameStart, out int classNameLength)
        {
            className       = null;
            classNameStart  = 0;
            classNameLength = 0;
            int    length = requiredNamespace.Length;
            string text   = el.Attribute("class");

            if (text == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NoClass"));
            }
            if (text.IndexOf('\'') >= 0)
            {
                text = text.Replace('\'', '"');
            }
            if (!PermissionToken.IsMscorlibClassName(text))
            {
                return(false);
            }
            int num = text.IndexOf(',');
            int num2;

            if (num == -1)
            {
                num2 = text.Length;
            }
            else
            {
                num2 = num;
            }
            if (num2 > length && text.StartsWith(requiredNamespace, StringComparison.Ordinal))
            {
                className       = text;
                classNameLength = num2 - length;
                classNameStart  = length;
                return(true);
            }
            return(false);
        }
        private static bool ParseElementForObjectCreation(SecurityElement el, string requiredNamespace, out string className, out int classNameStart, out int classNameLength)
        {
            className       = null;
            classNameStart  = 0;
            classNameLength = 0;
            int    length = requiredNamespace.Length;
            string str    = el.Attribute("class");

            if (str == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NoClass"));
            }
            if (str.IndexOf('\'') >= 0)
            {
                str = str.Replace('\'', '"');
            }
            if (PermissionToken.IsMscorlibClassName(str))
            {
                int num3;
                int index = str.IndexOf(',');
                if (index == -1)
                {
                    num3 = str.Length;
                }
                else
                {
                    num3 = index;
                }
                if ((num3 > length) && str.StartsWith(requiredNamespace, StringComparison.Ordinal))
                {
                    className       = str;
                    classNameLength = num3 - length;
                    classNameStart  = length;
                    return(true);
                }
            }
            return(false);
        }
Example #4
0
        ParseElementForObjectCreation(SecurityElement el,
                                      String requiredNamespace,
                                      out String className,
                                      out int classNameStart,
                                      out int classNameLength)
        {
            className       = null;
            classNameStart  = 0;
            classNameLength = 0;

            int requiredNamespaceLength = requiredNamespace.Length;

            String fullClassName = el.Attribute("class");

            if (fullClassName == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NoClass"));
            }

            if (fullClassName.IndexOf('\'') >= 0)
            {
                fullClassName = fullClassName.Replace('\'', '\"');
            }

            if (!PermissionToken.IsMscorlibClassName(fullClassName))
            {
                return(false);
            }

            int commaIndex = fullClassName.IndexOf(',');
            int namespaceClassNameLength;

            // If the classname is tagged with assembly information, find where
            // the assembly information begins.

            if (commaIndex == -1)
            {
                namespaceClassNameLength = fullClassName.Length;
            }
            else
            {
                namespaceClassNameLength = commaIndex;
            }

            // Only if the length of the class name is greater than the namespace info
            // on our requiredNamespace do we continue
            // with our check.

            if (namespaceClassNameLength > requiredNamespaceLength)
            {
                // Make sure we are in the required namespace.
                if (fullClassName.StartsWith(requiredNamespace, StringComparison.Ordinal))
                {
                    className       = fullClassName;
                    classNameLength = namespaceClassNameLength - requiredNamespaceLength;
                    classNameStart  = requiredNamespaceLength;
                    return(true);
                }
            }

            return(false);
        }