Пример #1
0
        public static void TransformFile(string hostsFile, params Func <IEnumerable <string>, IEnumerable <string> >[] transforms)
        {
            var encoding = HostsFileUtil.GetEncoding(hostsFile);
            IEnumerable <string> contents = File.ReadAllLines(hostsFile);

            foreach (var transform in transforms)
            {
                contents = transform(contents);
            }

            File.WriteAllLines(hostsFile, contents.ToArray(), encoding);
        }
Пример #2
0
        private static Func <IEnumerable <string>, IEnumerable <string> > GetRemoveTransform(Func <string, bool> doHostsMatch)
        {
            return(lines => lines.Where(l =>
            {
                var match = HostsFileUtil.TryGetHostsFileEntry(l);

                if (match == null)
                {
                    return true;
                }

                var matchedHost = match.Hostname;
                if (!doHostsMatch(matchedHost))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }));
        }