Esempio n. 1
0
        private static bool MatchesExtension(ExtensionType type, string path)
        {
            string extension = Path.GetExtension(path)?.ToLower();
            bool   isNull    = string.IsNullOrWhiteSpace(extension);

            if (type.HasFlag(ExtensionType.Empty))
            {
                return(isNull);
            }
            else if (type.HasFlag(ExtensionType.Any))
            {
                return(!isNull);
            }
            else
            {
                return(GetAllowedExtensions(type)?.Contains(extension) ?? false);
            }
        }
Esempio n. 2
0
        private static IEnumerable <string> GetAllowedExtensions(ExtensionType type)
        {
            var extensions = new List <string>();

            if (type.HasFlag(ExtensionType.Any | ExtensionType.Empty))
            {
                return(null);
            }

            foreach (ExtensionType activeType in type.GetFlags())
            {
                extensions.Add('.' + activeType.ToString().ToLower());
            }

            return(extensions);
        }