pass same file line

This commit is contained in:
ikpil 2023-04-29 12:33:34 +09:00
parent b30f3c7666
commit 39bb7e32b4
1 changed files with 62 additions and 52 deletions

View File

@ -4,11 +4,20 @@ using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
public class FileLocation
{
public required string Path { get; init; }
public required int Line { get; init; }
public required int Column { get; init; }
public required string Letter { get; init; }
};
public static class Program
{
private static List<FileLocation> CreateLocations(string path)
{
List<string> list = ((IEnumerable<string>) File.ReadAllLines(path)).Where<string>((Func<string, bool>) (line => line.Contains("error CS1061: "))).ToList<string>();
List<string> list = ((IEnumerable<string>)File.ReadAllLines(path)).Where<string>((Func<string, bool>)(line => line.Contains("error CS1061: "))).ToList<string>();
List<FileLocation> locations = new List<FileLocation>();
foreach (string input in list)
{
@ -36,13 +45,14 @@ public static class Program
locations.Add(fileLocation);
}
}
return locations;
}
private static void Change(FileLocation location)
{
string[] contents = File.ReadAllLines(location.Path);
List<string> list = ((IEnumerable<char>) contents[location.Line - 1].ToCharArray()).Select<char, string>((Func<char, string>) (x => x.ToString() ?? "")).ToList<string>();
List<string> list = ((IEnumerable<char>)contents[location.Line - 1].ToCharArray()).Select<char, string>((Func<char, string>)(x => x.ToString() ?? "")).ToList<string>();
list[location.Column - 2] = "[";
if (location.Letter == "x")
list[location.Column - 1] = "0]";
@ -50,16 +60,16 @@ public static class Program
list[location.Column - 1] = "1]";
else if (location.Letter == "z")
list[location.Column - 1] = "2]";
string str = string.Join("", (IEnumerable<string>) list);
string str = string.Join("", (IEnumerable<string>)list);
contents[location.Line - 1] = str;
//File.WriteAllLines(location.Path, contents);
File.WriteAllLines(location.Path, contents);
}
public static void Main(string[] args)
{
var locations = Program.CreateLocations("../../../../../error.log");
foreach (FileLocation location in locations)
Program.Change(location);
foreach (FileLocation location in locations.DistinctBy(x => x.Path + x.Line))
Change(location);
}
}