public static IEnumerable <string> GetSetHostTransform(IEnumerable <string> contents, string hostName, string address) { List <string> result = new List <string>(); var needsInsert = true; foreach (var line in contents) { if (!HostsFileUtil.IsLineAHostFilesEntry(line)) { result.Add(line); continue; } if (needsInsert) { result.Add(GetHostLine(hostName, address)); needsInsert = false; } result.Add(line); } if (needsInsert) { result.Add(GetHostLine(hostName, address)); needsInsert = false; } return(result); }
public static IEnumerable <HostsFileEntry> Get(string filepath = null) { filepath = filepath ?? GetHostsPath(); var lines = File.ReadAllLines(filepath); return(lines .Where(l => HostsFileUtil.IsLineAHostFilesEntry(l)) .Select(l => HostsFileUtil.GetHostsFileEntry(l))); }