internal static IMembershipCondition CreateMembershipCondition(SecurityElement el)
        {
            if (el == null || !el.Tag.Equals("IMembershipCondition"))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongElementType"), "<IMembershipCondition>"));
            }
            string text;
            int    num;
            int    num2;

            if (XMLUtil.ParseElementForObjectCreation(el, "System.Security.Policy.", out text, out num, out num2))
            {
                if (num2 <= 23)
                {
                    if (num2 != 22)
                    {
                        if (num2 == 23)
                        {
                            if (text[num] == 'H')
                            {
                                if (string.Compare(text, num, "HashMembershipCondition", 0, num2, StringComparison.Ordinal) == 0)
                                {
                                    return(new HashMembershipCondition());
                                }
                            }
                            else if (text[num] == 'S')
                            {
                                if (string.Compare(text, num, "SiteMembershipCondition", 0, num2, StringComparison.Ordinal) == 0)
                                {
                                    return(new SiteMembershipCondition());
                                }
                            }
                            else if (string.Compare(text, num, "ZoneMembershipCondition", 0, num2, StringComparison.Ordinal) == 0)
                            {
                                return(new ZoneMembershipCondition());
                            }
                        }
                    }
                    else if (text[num] == 'A')
                    {
                        if (string.Compare(text, num, "AllMembershipCondition", 0, num2, StringComparison.Ordinal) == 0)
                        {
                            return(new AllMembershipCondition());
                        }
                    }
                    else if (string.Compare(text, num, "UrlMembershipCondition", 0, num2, StringComparison.Ordinal) == 0)
                    {
                        return(new UrlMembershipCondition());
                    }
                }
                else if (num2 != 28)
                {
                    if (num2 != 29)
                    {
                        if (num2 == 39)
                        {
                            if (string.Compare(text, num, "ApplicationDirectoryMembershipCondition", 0, num2, StringComparison.Ordinal) == 0)
                            {
                                return(new ApplicationDirectoryMembershipCondition());
                            }
                        }
                    }
                    else if (string.Compare(text, num, "StrongNameMembershipCondition", 0, num2, StringComparison.Ordinal) == 0)
                    {
                        return(new StrongNameMembershipCondition());
                    }
                }
                else if (string.Compare(text, num, "PublisherMembershipCondition", 0, num2, StringComparison.Ordinal) == 0)
                {
                    return(new PublisherMembershipCondition());
                }
            }
            new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Assert();
            Type classFromElement = XMLUtil.GetClassFromElement(el, true);

            if (classFromElement == null)
            {
                return(null);
            }
            if (!typeof(IMembershipCondition).IsAssignableFrom(classFromElement))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NotAMembershipCondition"));
            }
            return((IMembershipCondition)Activator.CreateInstance(classFromElement, true));
        }
 // Token: 0x06002B87 RID: 11143 RVA: 0x000A2A15 File Offset: 0x000A0C15
 public static SecurityElement NewPermissionElement(IPermission ip)
 {
     return(XMLUtil.NewPermissionElement(ip.GetType().FullName));
 }
        public static IPermission CreatePermission(SecurityElement el, PermissionState permState, bool ignoreTypeLoadFailures)
        {
            if (el == null || (!el.Tag.Equals("Permission") && !el.Tag.Equals("IPermission")))
            {
                throw new ArgumentException(string.Format(null, Environment.GetResourceString("Argument_WrongElementType"), "<Permission>"));
            }
            string text;
            int    num;
            int    length;

            if (XMLUtil.ParseElementForObjectCreation(el, "System.Security.Permissions.", out text, out num, out length))
            {
                switch (length)
                {
                case 12:
                    if (string.Compare(text, num, "UIPermission", 0, length, StringComparison.Ordinal) == 0)
                    {
                        return(new UIPermission(permState));
                    }
                    break;

                case 16:
                    if (string.Compare(text, num, "FileIOPermission", 0, length, StringComparison.Ordinal) == 0)
                    {
                        return(new FileIOPermission(permState));
                    }
                    break;

                case 18:
                    if (text[num] == 'R')
                    {
                        if (string.Compare(text, num, "RegistryPermission", 0, length, StringComparison.Ordinal) == 0)
                        {
                            return(new RegistryPermission(permState));
                        }
                    }
                    else if (string.Compare(text, num, "SecurityPermission", 0, length, StringComparison.Ordinal) == 0)
                    {
                        return(new SecurityPermission(permState));
                    }
                    break;

                case 19:
                    if (string.Compare(text, num, "PrincipalPermission", 0, length, StringComparison.Ordinal) == 0)
                    {
                        return(new PrincipalPermission(permState));
                    }
                    break;

                case 20:
                    if (text[num] == 'R')
                    {
                        if (string.Compare(text, num, "ReflectionPermission", 0, length, StringComparison.Ordinal) == 0)
                        {
                            return(new ReflectionPermission(permState));
                        }
                    }
                    else if (string.Compare(text, num, "FileDialogPermission", 0, length, StringComparison.Ordinal) == 0)
                    {
                        return(new FileDialogPermission(permState));
                    }
                    break;

                case 21:
                    if (text[num] == 'E')
                    {
                        if (string.Compare(text, num, "EnvironmentPermission", 0, length, StringComparison.Ordinal) == 0)
                        {
                            return(new EnvironmentPermission(permState));
                        }
                    }
                    else if (text[num] == 'U')
                    {
                        if (string.Compare(text, num, "UrlIdentityPermission", 0, length, StringComparison.Ordinal) == 0)
                        {
                            return(new UrlIdentityPermission(permState));
                        }
                    }
                    else if (string.Compare(text, num, "GacIdentityPermission", 0, length, StringComparison.Ordinal) == 0)
                    {
                        return(new GacIdentityPermission(permState));
                    }
                    break;

                case 22:
                    if (text[num] == 'S')
                    {
                        if (string.Compare(text, num, "SiteIdentityPermission", 0, length, StringComparison.Ordinal) == 0)
                        {
                            return(new SiteIdentityPermission(permState));
                        }
                    }
                    else if (text[num] == 'Z')
                    {
                        if (string.Compare(text, num, "ZoneIdentityPermission", 0, length, StringComparison.Ordinal) == 0)
                        {
                            return(new ZoneIdentityPermission(permState));
                        }
                    }
                    else if (string.Compare(text, num, "KeyContainerPermission", 0, length, StringComparison.Ordinal) == 0)
                    {
                        return(new KeyContainerPermission(permState));
                    }
                    break;

                case 24:
                    if (string.Compare(text, num, "HostProtectionPermission", 0, length, StringComparison.Ordinal) == 0)
                    {
                        return(new HostProtectionPermission(permState));
                    }
                    break;

                case 27:
                    if (string.Compare(text, num, "PublisherIdentityPermission", 0, length, StringComparison.Ordinal) == 0)
                    {
                        return(new PublisherIdentityPermission(permState));
                    }
                    break;

                case 28:
                    if (string.Compare(text, num, "StrongNameIdentityPermission", 0, length, StringComparison.Ordinal) == 0)
                    {
                        return(new StrongNameIdentityPermission(permState));
                    }
                    break;

                case 29:
                    if (string.Compare(text, num, "IsolatedStorageFilePermission", 0, length, StringComparison.Ordinal) == 0)
                    {
                        return(new IsolatedStorageFilePermission(permState));
                    }
                    break;
                }
            }
            object[] args = new object[]
            {
                permState
            };
            new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Assert();
            Type classFromElement = XMLUtil.GetClassFromElement(el, ignoreTypeLoadFailures);

            if (classFromElement == null)
            {
                return(null);
            }
            if (!typeof(IPermission).IsAssignableFrom(classFromElement))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NotAPermissionType"));
            }
            return((IPermission)Activator.CreateInstance(classFromElement, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, null, args, null));
        }
Пример #4
0
        internal static IMembershipCondition CreateMembershipCondition(SecurityElement el)
        {
            if (el == null || !el.Tag.Equals("IMembershipCondition"))
            {
                throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongElementType"), (object)"<IMembershipCondition>"));
            }
            string className;
            int    classNameStart;
            int    classNameLength;

            if (XMLUtil.ParseElementForObjectCreation(el, "System.Security.Policy.", out className, out classNameStart, out classNameLength))
            {
                if (classNameLength <= 23)
                {
                    if (classNameLength != 22)
                    {
                        if (classNameLength == 23)
                        {
                            if ((int)className[classNameStart] == 72)
                            {
                                if (string.Compare(className, classNameStart, "HashMembershipCondition", 0, classNameLength, StringComparison.Ordinal) == 0)
                                {
                                    return((IMembershipCondition) new HashMembershipCondition());
                                }
                            }
                            else if ((int)className[classNameStart] == 83)
                            {
                                if (string.Compare(className, classNameStart, "SiteMembershipCondition", 0, classNameLength, StringComparison.Ordinal) == 0)
                                {
                                    return((IMembershipCondition) new SiteMembershipCondition());
                                }
                            }
                            else if (string.Compare(className, classNameStart, "ZoneMembershipCondition", 0, classNameLength, StringComparison.Ordinal) == 0)
                            {
                                return((IMembershipCondition) new ZoneMembershipCondition());
                            }
                        }
                    }
                    else if ((int)className[classNameStart] == 65)
                    {
                        if (string.Compare(className, classNameStart, "AllMembershipCondition", 0, classNameLength, StringComparison.Ordinal) == 0)
                        {
                            return((IMembershipCondition) new AllMembershipCondition());
                        }
                    }
                    else if (string.Compare(className, classNameStart, "UrlMembershipCondition", 0, classNameLength, StringComparison.Ordinal) == 0)
                    {
                        return((IMembershipCondition) new UrlMembershipCondition());
                    }
                }
                else if (classNameLength != 28)
                {
                    if (classNameLength != 29)
                    {
                        if (classNameLength == 39 && string.Compare(className, classNameStart, "ApplicationDirectoryMembershipCondition", 0, classNameLength, StringComparison.Ordinal) == 0)
                        {
                            return((IMembershipCondition) new ApplicationDirectoryMembershipCondition());
                        }
                    }
                    else if (string.Compare(className, classNameStart, "StrongNameMembershipCondition", 0, classNameLength, StringComparison.Ordinal) == 0)
                    {
                        return((IMembershipCondition) new StrongNameMembershipCondition());
                    }
                }
                else if (string.Compare(className, classNameStart, "PublisherMembershipCondition", 0, classNameLength, StringComparison.Ordinal) == 0)
                {
                    return((IMembershipCondition) new PublisherMembershipCondition());
                }
            }
            new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Assert();
            Type classFromElement = XMLUtil.GetClassFromElement(el, true);

            if (classFromElement == (Type)null)
            {
                return((IMembershipCondition)null);
            }
            if (!typeof(IMembershipCondition).IsAssignableFrom(classFromElement))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NotAMembershipCondition"));
            }
            return((IMembershipCondition)Activator.CreateInstance(classFromElement, true));
        }