System.Security.Util.TokenBasedSet.SetItem C# (CSharp) 메소드

SetItem() 개인적인 메소드

private SetItem ( int index, Object item ) : void
index int
item Object
리턴 void
        internal void SetItem(int index, Object item)
        {
            Object[] aObj = null;

            if (item == null)
            {
                RemoveItem(index);
                return;
            }

            switch (m_cElt)
            {
            case 0:
                // on the first item, we don't create an array, we merely remember it's index and value
                // this this the 99% case
                m_cElt = 1;
                m_maxIndex = (short)index;
                m_Obj = item;
                break;

            case 1:
                // we have to decide if a 2nd item has indeed been added and create the array
                // if it has
                if (index == m_maxIndex)
                {
                    // replacing the one existing item
                    m_Obj = item;
                 }
                else
                {
                    // adding a second distinct permission
                    Object objSaved = m_Obj;
                    int iMax = Math.Max(m_maxIndex, index);
                    
                    aObj = new Object[iMax+1];
                    aObj[m_maxIndex] = objSaved;
                    aObj[index] = item;
                    m_maxIndex = (short)iMax;
                    m_cElt = 2;
                    m_Set = aObj;
                    m_Obj = null;
                }
                break;

            default:
                // this is the general case code for when there is really an array

                aObj = m_Set;

                // we are now adding an item, check if we need to grow

                if (index >= aObj.Length)
                {
                    Object[] newset = new Object[index+1];
                    System.Array.Copy(aObj, 0, newset, 0, m_maxIndex+1);
                    m_maxIndex = (short)index;
                    newset[index] = item;
                    m_Set = newset;
                    m_cElt++;
                }
                else
                {
                    if (aObj[index] == null)
                        m_cElt++;

                    aObj[index] = item;

                    if (index > m_maxIndex)
                        m_maxIndex = (short)index;
                }
                break;
            }
        }

Usage Example

예제 #1
0
        // Used to merge two distinct TokenBasedSets (used currently only in PermissionSet Deserialization)
        internal TokenBasedSet SpecialUnion(TokenBasedSet other)
        {
            // This gets called from PermissionSet.OnDeserialized and it's possible that the TokenBasedSets have
            // not been subjected to VTS callbacks yet
            OnDeserializedInternal();
            TokenBasedSet unionSet = new TokenBasedSet();
            int           maxMax;

            if (other != null)
            {
                other.OnDeserializedInternal();
                maxMax = this.GetMaxUsedIndex() > other.GetMaxUsedIndex() ? this.GetMaxUsedIndex() : other.GetMaxUsedIndex();
            }
            else
            {
                maxMax = this.GetMaxUsedIndex();
            }

            for (int i = 0; i <= maxMax; ++i)
            {
                Object      thisObj  = this.GetItem(i);
                IPermission thisPerm = thisObj as IPermission;

                Object      otherObj  = (other != null)?other.GetItem(i):null;
                IPermission otherPerm = otherObj as IPermission;

                if (thisObj == null && otherObj == null)
                {
                    continue;
                }

                if (thisObj == null)
                {
                    PermissionToken token = PermissionToken.GetToken(otherPerm);

                    if (token == null)
                    {
                        throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
                    }

                    unionSet.SetItem(token.m_index, otherPerm);
                }
                else if (otherObj == null)
                {
                    PermissionToken token = PermissionToken.GetToken(thisPerm);
                    if (token == null)
                    {
                        throw new SerializationException(Environment.GetResourceString("Serialization_InsufficientState"));
                    }
                    unionSet.SetItem(token.m_index, thisPerm);
                }
                else
                {
                    Debug.Assert((thisObj == null || otherObj == null), "Permission cannot be in both TokenBasedSets");
                }
            }
            return(unionSet);
        }
All Usage Examples Of System.Security.Util.TokenBasedSet::SetItem