-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCodeFile.cs
More file actions
33 lines (30 loc) · 1.09 KB
/
CodeFile.cs
File metadata and controls
33 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
namespace LinesOfCodeCounter;
public record CodeFile
{
public FileInfo FileInfo { get; init; }
public string FileLocation { get; init; }
public string FileName { get; init; }
public string FileExtension { get; init; }
public long TotalLinesOfCode { get; set; }
public long TotalCharacterCount { get; set; }
public long LongestLineOfCode { get; set; }
public CodeFile(FileInfo fileInfo, string folderToExamine)
{
FileInfo = fileInfo ?? throw new ArgumentNullException(nameof(fileInfo));
FileName = Path.GetFileNameWithoutExtension(fileInfo.Name);
FileLocation = fileInfo.DirectoryName?.RemoveStartingMask(folderToExamine);
FileExtension = fileInfo.Extension ?? "UNKNOWN";
ReadFile();
}
void ReadFile()
{
using var reader = new StreamReader(FileInfo.FullName);
string? line;
while((line = reader.ReadLine()) != null)
{
TotalLinesOfCode++;
TotalCharacterCount += line.Length;
LongestLineOfCode = Math.Max(LongestLineOfCode, line.Length);
}
}
}