sectioncollection.cs

来自「完全网站系统」· CS 代码 · 共 137 行

CS
137
字号
namespace ASPNET.StarterKit.Communities {
    
    using System;
    using System.Collections;
    using System.Collections.Specialized;


    //*********************************************************************
    //
    // SectionCollection Class
    //
    // Represents a collection of SectionInfo objects representing 
    // community sections.
    //
    //*********************************************************************
    
    public class SectionCollection : Hashtable {
    
        ArrayList orderedSections = new ArrayList();
        Hashtable sectionsByID = new Hashtable();
        SectionInfo homeSection = null;


        //*********************************************************************
        //
        // Add Method
        //
        // Adds a new SectionInfo object to the collection. Also checkes
        // whether section is home section and adds to ordered collection. 
        //
        //*********************************************************************

        override public void Add(Object key, Object value) {
                SectionInfo _sectionInfo = (SectionInfo)value;

                // Don't allow duplicate values
                if (Contains(key))
                    return;

                
                if (_sectionInfo.ParentSectionID == -1)
                    homeSection = _sectionInfo; 
                    
                orderedSections.Add(_sectionInfo);
                sectionsByID.Add(_sectionInfo.ID, value); 
                base.Add(key, value);
        }
 

        //*********************************************************************
        //
        // this Indexer
        //
        // Adds a SectionInfo object. 
        //
        //*********************************************************************

        override public Object this[Object key] {
            set {
                // Don't allow duplicate values
                if (Contains(key))
                    return;

                orderedSections.Add(value);
                sectionsByID.Add(((SectionInfo)value).ID, value); 
                base[key] = value;
            }
        }

 
        //*********************************************************************
        //
        // this Indexer
        //
        // Returns a SectionInfo object based on path. 
        //
        //*********************************************************************

        public SectionInfo this[string path] {
            get {
                return (SectionInfo)base[path];
            }
        }    
 

        //*********************************************************************
        //
        // GetOrderedSections Method
        //
        // Returns an ordered list of sections. 
        //
        //*********************************************************************
        
        public ArrayList GetOrderedSections() {
            return orderedSections;
        }


        //*********************************************************************
        //
        // GetSectionByID Method
        //
        // Returns SectionInfo object from a section ID. 
        //
        //*********************************************************************
        
        public SectionInfo GetSectionByID(int sectionID) {
            return (SectionInfo)sectionsByID[sectionID];
        }
        

        //*********************************************************************
        //
        // DefaultSection Property
        //
        // Returns the default (home) section for a community. 
        //
        //*********************************************************************
        
        public SectionInfo DefaultSection {
            get { return homeSection; }
        }
        

        //*********************************************************************
        //
        // SectionCollection Constructor
        //
        // Initializes SectionCollection as a case-insensitive Hashtable. 
        //
        //*********************************************************************
        
        public SectionCollection() : base(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer() ) {}
        
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?