C#: Minimal update of relevant code to minimize project dependencies and hide some implementation details behind interfaces.

This commit is contained in:
Michael Nebel
2023-08-18 10:43:58 +02:00
parent f47e59dff1
commit c0d1179c8a
23 changed files with 181 additions and 147 deletions

View File

@@ -1,11 +1,11 @@
using Semmle.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Semmle.Util;
namespace Semmle.BuildAnalyser
namespace Semmle.Extraction.CSharp.DependencyFetching
{
// <summary>
@@ -145,22 +145,22 @@ namespace Semmle.BuildAnalyser
[GeneratedRegex("<(.*\\s)?Project.*\\sSdk=\"(.*?)\".*/?>", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline)]
private static partial Regex ProjectSdk();
}
}
internal interface IUnsafeFileReader
{
IEnumerable<string> ReadLines(string file);
}
internal class UnsafeFileReader : IUnsafeFileReader
{
public IEnumerable<string> ReadLines(string file)
internal interface IUnsafeFileReader
{
using var sr = new StreamReader(file);
string? line;
while ((line = sr.ReadLine()) != null)
IEnumerable<string> ReadLines(string file);
}
internal class UnsafeFileReader : IUnsafeFileReader
{
public IEnumerable<string> ReadLines(string file)
{
yield return line;
using var sr = new StreamReader(file);
string? line;
while ((line = sr.ReadLine()) != null)
{
yield return line;
}
}
}
}