Click here to Skip to main content
16,016,580 members

Bugs and Suggestions

   

General discussions, site bug reports and suggestions about the site.

For general questions check out the CodeProject FAQs. To report spam and abuse Head to the Spam and abuse watch. If you wish to report a bug privately, especially those related to security, please email webmaster@codeproject.com

 
GeneralRe: Univoter or... Pin
Abhinav S19-Oct-10 0:28
Abhinav S19-Oct-10 0:28 
GeneralRe: Univoter or... Pin
fjdiewornncalwe19-Oct-10 3:52
professionalfjdiewornncalwe19-Oct-10 3:52 
GeneralSpammer Pin
HimanshuJoshi18-Oct-10 18:09
HimanshuJoshi18-Oct-10 18:09 
GeneralRe: Spammer Pin
Chris Maunder19-Oct-10 1:37
cofounderChris Maunder19-Oct-10 1:37 
GeneralProblem in Q & A section Pin
Brij18-Oct-10 6:28
mentorBrij18-Oct-10 6:28 
GeneralRe: Problem in Q & A section Pin
Chris Maunder18-Oct-10 10:53
cofounderChris Maunder18-Oct-10 10:53 
GeneralRe: Problem in Q & A section Pin
Brij18-Oct-10 23:00
mentorBrij18-Oct-10 23:00 
GeneralHelp for publish , Wrong position of source code. Pin
yuan yong fu18-Oct-10 5:15
yuan yong fu18-Oct-10 5:15 
Hi editor.

I write a article use the following HTML code, when I publish , I find all source code (include XML and C#) move to the end automatic ,why?



<ul class="Download">
<li><a href="XLineCounter2010/XLineCounter.zip">Download XLineCounter - 313.13 KB</a></li>
</ul>

<h2>Introduction</h2>

<p ><span >XLineCounter is a open source C# program to analyze source code files and count number of source code line. It can count number of source line, comment line and blank line.</span></p>

<h2>Background</h2>

<p ><span >Million of programmers work hard year after year, and write many source codes in C++, C#, VB or Delphi. Some times they want know how many lines of those source code on earth. Of cause they can not count line by line, so they need a tool to count source lines.</span></p>

<h2>XLineCounter</h2>

<p ><span >Today, source code file is not alone, many source code file construct a project, and the compiler handle the project and generate program file.</span></p>

<p ><span >For example, in VS.NET2005, People create a C# project which file name’s extension is csproj, and add many C# source file to the C# project.</span></p>

<p ><span >XLineCounter need 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. So I design XLineCounter structure as the following shape.</span></p>

<p ><span ><img height="391" alt="XLineCounter_Structure.gif" src="XLineCounter2010/XLineCounter_Structure.gif" width="552" /></span></p>

<p ><span >There are two stresses in XLineCounter: first, analyze project file and get file list; second, analyze source file use specify syntax.</span></p>

<p ><span >For example, a C# .NET2005 project file in XML format, There is a sample.</span></p>

<p ><span >
<pre lang="XML">
&lt;Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
&lt;PropertyGroup&gt;
&lt;AssemblyName&gt;CellViewLib&lt;/AssemblyName&gt;
&lt;/PropertyGroup&gt;
&lt;ItemGroup&gt;
&lt;Reference Include="System"&gt;
&lt;Name&gt;System&lt;/Name&gt;
&lt;/Reference&gt;
&lt;/ItemGroup&gt;
&lt;ItemGroup&gt;
&lt;Content Include="App.ico" /&gt;
&lt;Compile Include="frmTestCellView.cs"&gt;
&lt;SubType&gt;Form&lt;/SubType&gt;
&lt;/Compile&gt;
&lt;EmbeddedResource Include="frmTestCellView.resx"&gt;
&lt;DependentUpon&gt;frmTestCellView.cs&lt;/DependentUpon&gt;
&lt;SubType&gt;Designer&lt;/SubType&gt;
&lt;/EmbeddedResource&gt;
&lt;/ItemGroup&gt;
&lt;/Project&gt;
</pre>
</span></p>

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

<p >

<span >

<pre lang="CS">
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(txt);
if (doc.DocumentElement.Name == "Project"
&& doc.DocumentElement.GetAttribute("xmlns") == "http://schemas.microsoft.com/developer/msbuild/2003")
{
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;
project.Files.Add(ProjFile);

System.Xml.XmlNamespaceManager ns = new System.Xml.XmlNamespaceManager(doc.NameTable);
ns.AddNamespace("a", "http://schemas.microsoft.com/developer/msbuild/2003");

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;
}
else
{
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;
}
else
{
NewFile.Style = FileStyle.None;
}
project.Files.Add(NewFile);
}//foreach
}
</pre>

</span></p>

<p ><span >Use this code , XLineCounter can get file list from C#2005 project file. In the same way, XLineCounter can analyze VB.NET2005, VB6.0, Delphi project file and get source code file list.</span></p>

<p ><span >Next, XLineCounter need analyze source code with some kind of syntax. For example, There are some C# source code as the following.</span></p>

<p ><span >



<pre lang="CS">
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(txt);
if (doc.DocumentElement.Name == "Project"
&& doc.DocumentElement.GetAttribute("xmlns") == "http://schemas.microsoft.com/developer/msbuild/2003")
{
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;
project.Files.Add(ProjFile);

System.Xml.XmlNamespaceManager ns = new System.Xml.XmlNamespaceManager(doc.NameTable);
ns.AddNamespace("a", "http://schemas.microsoft.com/developer/msbuild/2003");

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;
}
else
{
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;
}
else
{
NewFile.Style = FileStyle.None;
}
project.Files.Add(NewFile);
}//foreach
}
</pre>


</span></p>

<p ><span ></span><span >In C# syntax, there are three characters</span></p>

<p style="MARGIN-LEFT: 18pt; TEXT-INDENT: -18pt"><span >1.<span > </span></span><span >Single line comment starts with // .</span></p>

<p style="MARGIN-LEFT: 18pt; TEXT-INDENT: -18pt"><span >2.<span > </span></span><span >Multi-line comment starts with /* and end with */ .</span></p>

<p style="MARGIN-LEFT: 18pt; TEXT-INDENT: -18pt"><span >3.<span > </span></span><span >String data starts with double quotes and end with double quotes.</span></p>

<p style="MARGIN-LEFT: 18pt; TEXT-INDENT: -18pt"><span >4.<span > </span></span><span >In string data , \” define a double quotes characters.</span></p>

<p style="MARGIN-LEFT: 18pt; TEXT-INDENT: -18pt"><span >5.<span > </span></span><span >Multi-line string data starts with @” .</span></p>

<p><span >So I write the following C# code to analyze C# source code text.</span></p>

<p><span >


<pre lang="CS">
// Single line comment
string str = "abc";
string str2 = @"abc
efg";
/*
Multi-line comment
*/
</pre>



</span></p>

<p><span ></span><span >LineInfo type is a class which contains information of a source code line, It define as the following</span></p>

<p><span >
<pre lang="CS">
// 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 &lt; info.LineText.Length ; iCount ++)
{
// Get current character
char c = info.LineText[iCount] ;
// Get next character
char c2 = (char)0;
if( iCount &lt; info.LineText.Length - 1 )
c2 = info.LineText[ iCount + 1 ];

if(! char.IsWhiteSpace( c ))
info.BlankLine = false;

// Defineing 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 &gt; 0 )
info.CodeFlag = true;
info.CommentFlag = true;
DefineComment = true;
iCount ++ ;
continue;
}
}
if( c == '\"')
{
if( iCount &lt; 0 && info.LineText[iCount-1] == '@')
// Start muli-line string when meet @"
DefineString = 2 ;
else
// Start single line string when meet "
DefineString = 1 ;
}
}
else
{
info.BlankLine = false;
// Defining string
if( c == '\"' )
{
// Finish string when meet "
if( iCount &lt; 0 && info.LineText[iCount-1] !='\\' )
DefineString = 0 ;
}
}
if( ! char.IsWhiteSpace( c ))
info.CodeFlag = true;
}//for(int iCount = 0 ; iCount &lt; info.LineText.Length ; iCount ++)
NextLine:;
}//foreach( LineInfo info in myLines )
</pre></span></p>

<p><span ></span><span >By using upper code, XLineCounter can analyze C#.NET2005 project file and C# source code, count number of C# source code. In the same way , XLineCounter can count number of source code of VB.NET, Delphi and C++.</span></p>

<p ><span >This is a snapshot of XLineCounter.</span></p>

<p><img height="490" alt="XLineCounter_Snapshot.jpg" src="XLineCounter2010/XLineCounter_Snapshot.jpg" width="571" />. </p>

<h2>Points of Interest</h2>

<p>None.</p>

<h2>History</h2>

<p>None.</p>

yfyuan
GeneralRe: Help for publish , Wrong position of source code. Pin
Sean Ewington18-Oct-10 5:53
staffSean Ewington18-Oct-10 5:53 
GeneralRe: Help for publish , Wrong position of source code. Pin
Dalek Dave18-Oct-10 8:49
professionalDalek Dave18-Oct-10 8:49 
GeneralVisual Studio Addin? Pin
LloydA11117-Oct-10 7:04
LloydA11117-Oct-10 7:04 
GeneralCPOL Request Pin
Hans Dietrich16-Oct-10 11:13
mentorHans Dietrich16-Oct-10 11:13 
GeneralRe: CPOL Request Pin
Nish Nishant18-Oct-10 5:51
sitebuilderNish Nishant18-Oct-10 5:51 
GeneralRe: CPOL Request Pin
Hans Dietrich18-Oct-10 6:38
mentorHans Dietrich18-Oct-10 6:38 
GeneralRe: CPOL Request Pin
Nish Nishant18-Oct-10 6:54
sitebuilderNish Nishant18-Oct-10 6:54 
GeneralRe: CPOL Request Pin
Chris Maunder18-Oct-10 5:55
cofounderChris Maunder18-Oct-10 5:55 
GeneralRe: CPOL Request Pin
Hans Dietrich18-Oct-10 6:41
mentorHans Dietrich18-Oct-10 6:41 
GeneralRe: CPOL Request Pin
Chris Maunder18-Oct-10 10:48
cofounderChris Maunder18-Oct-10 10:48 
GeneralRe: CPOL Request Pin
Nish Nishant18-Oct-10 6:55
sitebuilderNish Nishant18-Oct-10 6:55 
GeneralRe: CPOL Request Pin
Hans Dietrich18-Oct-10 8:18
mentorHans Dietrich18-Oct-10 8:18 
GeneralMenu Naming Inconsistency [modified] Pin
DaveAuld16-Oct-10 6:08
professionalDaveAuld16-Oct-10 6:08 
GeneralSmall bug with pre formatting Pin
William Winner15-Oct-10 7:21
William Winner15-Oct-10 7:21 
GeneralRe: Small bug with pre formatting Pin
Chris Maunder15-Oct-10 10:44
cofounderChris Maunder15-Oct-10 10:44 
GeneralSuggestion for Reducing Univoters Pin
Nagy Vilmos15-Oct-10 3:25
professionalNagy Vilmos15-Oct-10 3:25 
GeneralRe: Suggestion for Reducing Univoters Pin
Dalek Dave15-Oct-10 3:47
professionalDalek Dave15-Oct-10 3:47 

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.