System.Security.Permissions.ResourcePermissionBase.IntersectContents C# (CSharp) Method

IntersectContents() private method

private IntersectContents ( object currentContent, object targetContent ) : object
currentContent object
targetContent object
return object
        private object IntersectContents(object currentContent, object targetContent) {
            if (currentContent is int) {
                int currentAccess = (int)currentContent;
                int targetAccess = (int)targetContent;
                return  (currentAccess & targetAccess);
            }
            else {
                Hashtable newContents = CreateHashtable();

                //Before executing the intersect operation, need to
                //resolve the "." entries
                object currentLocalContent = ((Hashtable)currentContent)[Local];
                object currentComputerNameContent = ((Hashtable)currentContent)[ComputerName];
                if (currentLocalContent != null || currentComputerNameContent != null) {
                    object targetLocalContent = ((Hashtable)targetContent)[Local];
                    object targetComputerNameContent = ((Hashtable)targetContent)[ComputerName];
                    if (targetLocalContent != null || targetComputerNameContent != null) {
                        object currentLocalMergedContent = currentLocalContent;
                        if (currentLocalContent != null && currentComputerNameContent != null)
                            currentLocalMergedContent = UnionOfContents(currentLocalContent, currentComputerNameContent);
                        else if (currentComputerNameContent != null)
                            currentLocalMergedContent = currentComputerNameContent;

                        object targetLocalMergedContent = targetLocalContent;
                        if (targetLocalContent != null && targetComputerNameContent != null)
                            targetLocalMergedContent = UnionOfContents(targetLocalContent, targetComputerNameContent);
                        else if (targetComputerNameContent != null)
                            targetLocalMergedContent = targetComputerNameContent;

                        object computerNameValue = IntersectContents(currentLocalMergedContent, targetLocalMergedContent);
                        if (HasContent(computerNameValue)) {
                            // There should be no computer name key added if the information
                            // was not specified in one of the targets
                            if (currentComputerNameContent != null || targetComputerNameContent != null) {
                                newContents[ComputerName] = computerNameValue;
                            }
                            else {
                                newContents[Local] = computerNameValue;
                            }
                        }
                    }
                }

                IDictionaryEnumerator contentEnumerator;
                Hashtable contentsTable;
                if (((Hashtable)currentContent).Count <  ((Hashtable)targetContent).Count) {
                    contentEnumerator = ((Hashtable)currentContent).GetEnumerator();
                    contentsTable = ((Hashtable)targetContent);
                }
                else{
                    contentEnumerator = ((Hashtable)targetContent).GetEnumerator();
                    contentsTable = ((Hashtable)currentContent);
                }

                //The wildcard entries intersection should be treated
                //as any other entry.
                while(contentEnumerator.MoveNext()) {
                    string currentKey = (string)contentEnumerator.Key;
                    if (contentsTable.ContainsKey(currentKey) &&
                          currentKey != Local &&
                          currentKey != ComputerName)  {

                        object currentValue = contentEnumerator.Value;
                        object targetValue = contentsTable[currentKey];
                        object newValue = IntersectContents(currentValue, targetValue);
                        if (HasContent(newValue))
                            newContents[currentKey] = newValue;
                    }
                }

                return (newContents.Count > 0) ? newContents : null;
            }
        }