示例#1
0
 Whitelist(List <string> lines)
 {
     _entries = lines.Select(line =>
     {
         if (WhitelistKey.TryParse(line, out var entry))
         {
             return(entry);
         }
         return(null);
     }).Where(entry => entry != null)
                .ToList();
     _assemblyNames = new HashSet <string>(_entries.Select(e => e.AssemblyName).Distinct(StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase);
 }
示例#2
0
        public static bool TryParse(string text, out WhitelistKey entry)
        {
            var assemblyNameIndex = text.LastIndexOf(',');

            if (assemblyNameIndex < 0)
            {
                entry = null;
                return(false);
            }

            var assemblyName = text.Substring(assemblyNameIndex + 1).Trim();
            var path         = text.Substring(0, assemblyNameIndex).Trim();
            var regexPattern = "\\A" + Regex.Escape(path.Replace('+', '.')).Replace("\\*", ".*") + "\\z";
            var regex        = new Regex(regexPattern, RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

            entry = new WhitelistKey(assemblyName, path, regex);
            return(true);
        }