📄 sourcefile.cs
字号:
using System;
namespace CodeAnalysis
{
/// <summary>
/// Summary description for SourceFile.
/// </summary>
public class SourceFile
{
public SourceFile(string fullPath)
{
m_linesOfCode =0;
m_classNames =new string [10 ];
m_classCount =0;
m_fullPath = fullPath;
try
{
System.IO.StreamReader reader =new
System.IO.StreamReader(m_fullPath);
int nameStart;
string oneline;
while ((oneline =reader.ReadLine())!=null)
{
oneline =oneline.Trim();
//Don 抰 count blank or comment lines.
if ((oneline !="")&&(!oneline.StartsWith("\\")))
{
m_linesOfCode++;
}
if (oneline.StartsWith("public class "))
{
nameStart =oneline.IndexOf("class ")+6;
char [] separators = {' ', '\t', '{'};
string [] names = oneline.Substring(nameStart).Trim().Split(separators);
string className =names [0 ].Trim();
m_classNames [m_classCount++] = className;
}
}
reader.Close();
}
catch (System.Exception ex)
{
throw new System.Exception("Problems parsing source file:"
+ex.Message);
}
}
private string m_fullPath;
private int m_linesOfCode;
private string [] m_classNames;
private int m_classCount;
///<summary>
///Returns the full path of the source file.
///</summary>
public string FullPath
{
get {return m_fullPath;}
}
///<summary>
///Returns the filename, without path of the source file.
///</summary>
public string FileName
{
get
{
int lastSlash = m_fullPath.LastIndexOf("\\");
return m_fullPath.Substring(lastSlash +1);
}
}
//Visual C#
///<summary>
///The total number of classes defined in the source file.
///</summary>
public int ClassCount
{
get {return m_classCount;}
}
///<summary>
///Lines of code in the source file, excluding blank and comment lines.
///</summary>
public int LinesOfCode
{
get {return m_linesOfCode;}
}
//Visual C#
///<summary>
///Returns one of the names of the classes defined in the
///source file,based on an index.
///</summary>
///<param name="index">A zero-based index</param>
///<returns>A class name</returns>
public string GetClass(int index)
{
if (index <m_classCount)
{
return m_classNames [index ];
}
else
{
throw new System.IndexOutOfRangeException("There are only "
+m_classCount +" classes defined..");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -