Click here to Skip to main content
12,816,775 members (33,098 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


14 bookmarked
Posted 24 Jun 2012

XDD-Tools for developer

, 24 Jun 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
XDD-Tools for developer , count source code line,copy project file, remove comment in source code.


XDD (XDesigner.Development) is a tool for software developers written by yuan yong fu. It is open source. It can analyse VB, C++, C#, Delphi projects and count the number of source code lines, copy project files clearly; back up source files without wasting file and VSS information.

This is the project site:; (you can download the last version).

Autor's; blog site:


Millions of programmers work hard year after year, and write many source codes in C++, C#, VB or Delphi. Sometimes, they want know how many lines are there of that source code,Back file without any temp file which create by IDE. Of course, they cannot do it by hand, so they need a tool to do this.

Using the code

Today, source code files are not alone, many source code files construct a project, and the compiler handles the project and generates a program file.

For example, in VS.NET 2005, people create a C# project whose file name’s extension is csproj, and add many C# source files to the C# project.

XDD needs to analyze develop project file and get a list of source code file, also equip source code analyzer which can analyze source code like VB , C# or Pascal.

For example, a C# .NET2005 project file in XML format. There is a sample.

<Project DefaultTargets="Build"
    <Reference Include="System">
    <Content Include="App.ico" />
    <Compile Include="frmTestCellView.cs">
    <EmbeddedResource Include="frmTestCellView.resx">

To this XML document, I can execute XPath “Project/ItemGroup/Compile” and get a list of C# source file names. So I write the following C# code:

System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
if (doc.DocumentElement.Name == "Project"
    && doc.DocumentElement.GetAttribute("xmlns") == 
    "<a href="" + 
    "2003"></a />")
    project.ProjectFileName = strFileName;
    project.RootPath = System.IO.Path.GetDirectoryName(strFileName);
    ProjectFile ProjFile = new ProjectFile();
    ProjFile.FileName = System.IO.Path.GetFileName(strFileName);
    ProjFile.FullFileName = strFileName;
    ProjFile.Style = FileStyle.None;
    System.Xml.XmlNamespaceManager ns = 
       new System.Xml.XmlNamespaceManager(doc.NameTable);
    ns.AddNamespace("a", "<a href="" + 
       "/developer/msbuild/2003">" + 
       "developer/msbuild/2003</a />");
    System.Xml.XmlNode NameNode = doc.SelectSingleNode
  ("a:Project/a:PropertyGroup/a:AssemblyName", ns);
    if (NameNode != null)
        project.Name = NameNode.InnerText;
    foreach (System.Xml.XmlElement element in doc.SelectNodes
 ("a:Project/a:ItemGroup/*[name()='Compile' or name()='None' or 
 name()='EmbeddedResource' or name()='Content']", ns))
        string file = element.GetAttribute("Include");
        ProjectFile NewFile = new ProjectFile();
        NewFile.FileName = project.FixFileName(file);
        if (System.IO.Path.IsPathRooted(file))
            NewFile.FullFileName = file;
            NewFile.FullFileName = System.IO.Path.Combine(project.RootPath, file);
        if (element.Name == "Compile")
            NewFile.Style = FileStyle.SourceCode;
        else if (element.Name == "EmbeddedResource")
            NewFile.Style = FileStyle.Resource;
            NewFile.Style = FileStyle.None;

Using this code, XDD can get a file list from C#2005 project file. In the same way, XDD can analyze VB.NET 2005, VB6.0, Delphi project file and get source code file list.

Next, XDD needs to analyze source code with some kind of syntax. For example, there are some C# source code as follows:

// string define flag 
// 0:It is not define string
// 1:It is a singleline string
// 2:It is a multi-line string
int DefineString = 0;
// Comment flag
bool DefineComment = false ;
foreach( LineInfo info in myLines )
 info.CodeFlag = false;
 if( info.LineText.Length == 0 && DefineString == 2)
  info.BlankLine = false;
 for(int iCount = 0 ; iCount < info.LineText.Length ; iCount ++)
  // Get current character
  char c = info.LineText[iCount] ;
  // Get next character
  char c2 = (char)0;
  if( iCount < info.LineText.Length - 1 )
   c2 = info.LineText[ iCount + 1 ];
  if(! char.IsWhiteSpace( c ))
   info.BlankLine = false;
  // Defining Comment
  if( DefineComment )
   info.BlankLine = false;
   info.CommentFlag = true;
   // Finish when meet */
   if( c == '*' &&  c2 == '/' )
    DefineComment = false;
    iCount ++ ;
   continue ;
  if( DefineString == 0 )
   // Is not defining string
   if( c == '/' && c2 != 0 )
    if( c2 == '/' )
     // Single line comment when meet //
     info.CommentFlag = true;
     DefineComment = false;
     goto NextLine ;
    if( c2 == '*' )
     // Start multi-line comment when meet /*
     if( iCount > 0 )
      info.CodeFlag = true;
     info.CommentFlag = true;
     DefineComment = true;
     iCount ++ ;
   if( c == '\"')
    if( iCount < 0 && info.LineText[iCount-1] == 
             <a href="mailto:'@'">'@'</a />

LineInfo type is a class which contains information of a source code line. It is defined as follows:

/// <summary>
/// source code line information
/// </summary>
public class LineInfo
    /// <summary>
    /// Whether a text line
    /// </summary>
    public string LineText = null;
    /// <summary>
    /// Whether is a comment line
    /// </summary>
    public bool CommentFlag = false;
    /// <summary>
    /// Whether is a blank line , without any content
    /// </summary>
    public bool BlankLine = true;
    /// <summary>
    /// Whether is a source code line
    /// </summary>
    public bool CodeFlag = false;

By using the above code, XLineCounter can analyze C#.NET 2005 project files and C# source code, count the number of C# source code lines. In the same way, XLineCounter can count the number of source code lines of VB.NET, Delphi and C++.

Points of Interest



2012-6-24: First release.


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


About the Author

yuan yong fu
Web Developer duchang soft
China China
yuan yong fu of duchang soft , come from CHINA , 2008 Microsoft MVP,Use GDI+,XML/XSLT, site:

You may also be interested in...


Comments and Discussions

QuestionYour Articles Pin
Warrick Procter17-Oct-13 23:35
memberWarrick Procter17-Oct-13 23:35 
QuestionGreat ! Pin
Wrangly16-Oct-12 4:51
memberWrangly16-Oct-12 4:51 
GeneralMy vote of 5 Pin
Member 179611724-Jun-12 7:51
memberMember 179611724-Jun-12 7:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170308.1 | Last Updated 24 Jun 2012
Article Copyright 2012 by yuan yong fu
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid