public void AddPermission(CodeAccessPermission perm, int type)
        {
            //BCLDebug.Assert(type == MatchAssert || type == MatchDeny, "type == MatchAssert || type == MatchDeny");

            // can't get token if perm is null
            if (perm == null)
            {
                return;
            }

            PermissionToken permToken = PermissionToken.GetToken(perm);
            PermissionList  plist     = GetListForToken(permToken, true);

            plist.AppendPermission(perm, type);
        }
Example #2
0
     private void AppendTokenBasedSets( TokenBasedSet thisSet, TokenBasedSet permSet, int type, bool unrestricted )
     {
         int thisMaxIndex = thisSet.GetMaxUsedIndex();
         int permMaxIndex = permSet == null ? 0 : permSet.GetMaxUsedIndex();
         int maxIndex = thisMaxIndex > permMaxIndex ? thisMaxIndex : permMaxIndex;
         
         // Loop over the relevant indexes...
         for (int i = 0; i <= maxIndex; i++)
         {
             PermissionList plist = (PermissionList)thisSet.GetItem(i);
             CodeAccessPermission cap = permSet == null ? null : (CodeAccessPermission)permSet.GetItem(i);
             
             if (plist == null)
             {
                 if (this.m_unrestricted)
                 {
                     switch (type)
                     {
                     case PermissionList.MatchChecked:
                     case PermissionList.MatchPermitOnly:
                         plist = new PermissionList();
                         plist.AppendPermission(cap, type);
                         thisSet.SetItem( i, plist );
                         break;
                     
                     case PermissionList.MatchDeny:
                     case PermissionList.MatchAssert:
                         if (cap != null)
                         {
                             plist = new PermissionList();
                             plist.AppendPermission(cap, type);
                             thisSet.SetItem( i, plist );
                         }
                         break;
                     
                     default:
                         throw new ArgumentException(Environment.GetResourceString( "Argument_InvalidPermissionListType" ));
                     }
                 }
             }
             else
             {                    
                 // A list already exists. All lists should have at least
                 // one element in them.
 
                 // Normally, only append if the permission is not null.
                 // However, if the type is Checked, then make sure the
                 // list is terminated with a permission, null or not.
                 switch (type)
                 {
                 case PermissionList.MatchChecked:
                 case PermissionList.MatchPermitOnly:
                     plist.AppendPermissionAndCompress(cap, type);
                     break;
                         
                 case PermissionList.MatchDeny:
                 case PermissionList.MatchAssert:
                     if (cap != null)
                         plist.AppendPermissionAndCompress(cap, type);
                     break;
                         
                 default:
                     throw new ArgumentException(Environment.GetResourceString( "Argument_InvalidPermissionListType" ));
                 }
             }
         }
     }
        private void AppendTokenBasedSets(TokenBasedSet thisSet, TokenBasedSet permSet, int type, bool unrestricted)
        {
            int thisMaxIndex = thisSet.GetMaxUsedIndex();
            int permMaxIndex = permSet == null ? 0 : permSet.GetMaxUsedIndex();
            int maxIndex     = thisMaxIndex > permMaxIndex ? thisMaxIndex : permMaxIndex;

            // Loop over the relevant indexes...
            for (int i = 0; i <= maxIndex; i++)
            {
                PermissionList       plist = (PermissionList)thisSet.GetItem(i);
                CodeAccessPermission cap   = permSet == null ? null : (CodeAccessPermission)permSet.GetItem(i);

                if (plist == null)
                {
                    if (this.m_unrestricted)
                    {
                        switch (type)
                        {
                        case PermissionList.MatchChecked:
                        case PermissionList.MatchPermitOnly:
                            plist = new PermissionList();
                            plist.AppendPermission(cap, type);
                            thisSet.SetItem(i, plist);
                            break;

                        case PermissionList.MatchDeny:
                        case PermissionList.MatchAssert:
                            if (cap != null)
                            {
                                plist = new PermissionList();
                                plist.AppendPermission(cap, type);
                                thisSet.SetItem(i, plist);
                            }
                            break;

                        default:
                            throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionListType"));
                        }
                    }
                }
                else
                {
                    // A list already exists. All lists should have at least
                    // one element in them.

                    // Normally, only append if the permission is not null.
                    // However, if the type is Checked, then make sure the
                    // list is terminated with a permission, null or not.
                    switch (type)
                    {
                    case PermissionList.MatchChecked:
                    case PermissionList.MatchPermitOnly:
                        plist.AppendPermissionAndCompress(cap, type);
                        break;

                    case PermissionList.MatchDeny:
                    case PermissionList.MatchAssert:
                        if (cap != null)
                        {
                            plist.AppendPermissionAndCompress(cap, type);
                        }
                        break;

                    default:
                        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionListType"));
                    }
                }
            }
        }