Click here to Skip to main content
15,896,063 members
Articles / Programming Languages / C#

XDD-Tools for developer

Rate me:
Please Sign up or sign in to vote.
5.00/5 (9 votes)
24 Jun 2012CPOL2 min read 22.6K   449   14  
XDD-Tools for developer , count source code line,copy project file, remove comment in source code.
// ���� Ԭ����( http://www.xdesigner.cn ) 2007-5-13
using System;
using System.Collections ;
using System.Collections.Generic ;

namespace XDesigner.Development.Dom
{
	public abstract class FileAnalyser
	{
        static FileAnalyser()
        {
            AddAnalyser(".cs", new CSFileAnalyser());
            AddAnalyser(".c", new CFileAnalyser());
            AddAnalyser(".cpp", new CFileAnalyser());
            AddAnalyser(".js", new CFileAnalyser());
            AddAnalyser(".h", new CFileAnalyser());
            AddAnalyser(".cxx", new CFileAnalyser());
            AddAnalyser(".vb", new VBFileAnalyser());
            AddAnalyser(".cls", new VBFileAnalyser());
            AddAnalyser(".bas", new VBFileAnalyser());
            AddAnalyser(".vbs", new VBFileAnalyser());
            AddAnalyser(".frm", new VBFileAnalyser());
            AddAnalyser(".ctl", new VBFileAnalyser());
            AddAnalyser(".pas", new PascalFileAnalyser());
        }
        private static Dictionary<string, FileAnalyser> _Analysers = new Dictionary<string, FileAnalyser>();
        /// <summary>
        /// ע���ļ�������
        /// </summary>
        /// <param name="extersion">�ļ���չ��</param>
        /// <param name="analyser">�ļ�����������</param>
        public static void AddAnalyser(string extersion, FileAnalyser analyser)
        {
            if (string.IsNullOrEmpty(extersion))
            {
                throw new ArgumentNullException("extersion");
            }
            if (analyser == null)
            {
                throw new ArgumentNullException("analyser");
            }
            extersion = extersion.Trim().ToLower();
            _Analysers[extersion] = analyser;
        }

        /// <summary>
        /// ����ļ�������
        /// </summary>
        /// <param name="extersion">�ļ���չ��</param>
        /// <returns>�ļ�������</returns>
        public static FileAnalyser GetAnalyser(string extersion)
        {
            if (string.IsNullOrEmpty(extersion))
            {
                throw new ArgumentNullException("extersion");
            }
            extersion = extersion.Trim().ToLower();
            if (_Analysers.ContainsKey(extersion))
            {
                return _Analysers[extersion];
            }
            else
            {
                return null;
            }
        }

		public virtual bool CheckFileName( string strFileName )
		{
			return this.CheckFileExtension( FileHelper.GetExtension( strFileName ));
		}
		public virtual bool CheckFileExtension( string strExtension )
		{
			return false;
		}
		
		protected System.Collections.ArrayList myLines = new System.Collections.ArrayList();
		public virtual bool Analyse( FileElement file )
		{
			myLines.Clear();
			System.IO.FileInfo finfo = new System.IO.FileInfo( file.FullFileName );
			file.FileSize = (int) finfo.Length ;
			
			using( System.IO.StreamReader myReader = new System.IO.StreamReader( file.FullFileName , System.Text.Encoding.Default , true ))
			{
				string strLine = myReader.ReadLine();
				while( strLine != null)
				{
					LineInfo info = new LineInfo();
					info.LineText = strLine ;
					myLines.Add( info );
					file.CharCount += ( strLine.Length + 2 );
					strLine = myReader.ReadLine();
				}
				myReader.Close();
			}//using
			InnerAnalyse();
			file.LineCount = myLines.Count ;
			file.CommentCount = 0 ;
			file.CodeCount = 0 ;
			file.BlankCount = 0 ;
			foreach( LineInfo info in myLines )
			{
				if( info.CommentFlag )
					file.CommentCount ++ ;
				if( info.CodeFlag )
					file.CodeCount ++ ;
				if( info.BlankLine )
					file.BlankCount ++ ;
			}
			myLines.Clear();
			return true ;
		}
		protected virtual void InnerAnalyse()
		{
		}

        public virtual bool HandleComment(string fileName , bool removeComment, string headerComment)
        {
            return false;
        }
	}//public class FileAnalyser
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer duchang soft
China China
yuan yong fu of duchang soft , come from CHINA , 2008 Microsoft MVP,Use GDI+,XML/XSLT, site:http://www.cnblogs.com/xdesigner/

Comments and Discussions