System.Security.Permissions.ResourcePermissionBase.AddPermissionAccess C# (CSharp) Метод

AddPermissionAccess() защищенный Метод

protected AddPermissionAccess ( ResourcePermissionBaseEntry entry ) : void
entry ResourcePermissionBaseEntry
Результат void
        protected void AddPermissionAccess(ResourcePermissionBaseEntry entry) {
            if (entry == null)
                throw new ArgumentNullException("entry");

            if (entry.PermissionAccessPath.Length != this.TagNames.Length)
                throw new InvalidOperationException(SR.GetString(SR.PermissionNumberOfElements));

            Hashtable currentTable = this.rootTable;
            string[] accessPath = entry.PermissionAccessPath;
            for (int index = 0; index < accessPath.Length - 1; ++ index) {
                if (currentTable.ContainsKey(accessPath[index]))
                    currentTable = (Hashtable)currentTable[accessPath[index]];
                else {
                    Hashtable newHashTable = CreateHashtable();
                    currentTable[accessPath[index]] = newHashTable;
                    currentTable = newHashTable;
                }
            }

            if (currentTable.ContainsKey(accessPath[accessPath.Length - 1]))
                throw new InvalidOperationException(SR.GetString(SR.PermissionItemExists));

            currentTable[accessPath[accessPath.Length - 1]] = entry.PermissionAccess;
        }

Usage Example

Пример #1
0
        public override IPermission Union(IPermission target)
        {
            ResourcePermissionBase rpb = Cast(target);

            if (rpb == null)
            {
                return(Copy());
            }
            if (IsEmpty() && rpb.IsEmpty())
            {
                return(null);
            }
            if (rpb.IsEmpty())
            {
                return(Copy());
            }
            if (IsEmpty())
            {
                return(rpb.Copy());
            }

            bool unrestricted             = (IsUnrestricted() || rpb.IsUnrestricted());
            ResourcePermissionBase result = CreateFromType(this.GetType(), unrestricted);

            // strangely unrestricted union doesn't process the elements (while intersect does)
            if (!unrestricted)
            {
                foreach (ResourcePermissionBaseEntry entry in _list)
                {
                    result.AddPermissionAccess(entry);
                }
                foreach (ResourcePermissionBaseEntry entry in rpb._list)
                {
                    // don't add twice
                    if (!result.Exists(entry))
                    {
                        result.AddPermissionAccess(entry);
                    }
                }
            }
            return(result);
        }
All Usage Examples Of System.Security.Permissions.ResourcePermissionBase::AddPermissionAccess