commentcollection.cs

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

CS
109
字号
namespace ASPNET.StarterKit.Communities {

    using System;
    using System.Collections;


    //*********************************************************************
    //
    // CommentCollection Class
    //
    // This class represents a collection of comments.
    // It inherits from an ArrayList and uses a Hashtable internally. 
    //
    //*********************************************************************

    public class CommentCollection : ArrayList {
    
        Hashtable hashComments = new Hashtable();
    
    
        //*********************************************************************
        //
        // CommentCollection Constructor
        //
        // Initializes a new instance of the CommentCollection class. 
        //
        //*********************************************************************
    
        public CommentCollection() : base() {}


        //*********************************************************************
        //
        // this indexer
        //
        // Adds a new comment to the ArrayList and Hashtable. 
        //
        //*********************************************************************

        override public object this[int index] {
            set {
                hashComments[((CommentInfo)value).ContentPageID] = value;
                base[index] = value;
            }
            get {
                return (CommentInfo)base[index];
            }    
        }


        //*********************************************************************
        //
        // Add Method
        //
        // Adds a new comment to the ArrayList and Hashtable. 
        //
        //*********************************************************************

        override public int Add(object value) {
                hashComments[((CommentInfo)value).ContentPageID] = value;
                return base.Add(value);
        }


        //*********************************************************************
        //
        // GetChildren Method
        //
        // Gets all the immediate child comments by iterating through
        // the ArrayList. 
        //
        //*********************************************************************
        
        public CommentCollection GetChildren(int replyID) {
            CommentCollection colChildren = new CommentCollection();
         
            IEnumerator e = this.GetEnumerator();
            while (e.MoveNext())
                if (((CommentInfo)e.Current).ReplyID == replyID)
                    colChildren.Add(e.Current);
            return colChildren;
        }
        
        
        //*********************************************************************
        //
        // GetReplyLevel Method
        //
        // Gets the nesting level of a comment. 
        //
        //*********************************************************************
        
        public int GetReplyLevel(CommentInfo comment) {
            int level = -1;
            
            while (comment != null) {
                level ++;
                comment = (CommentInfo)hashComments[comment.ReplyID];
                
                if (level > 50)
                    break;
            }
            return level;
        }
        
        
    }
}

⌨️ 快捷键说明

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