Пример #1
0
        private static MimeTypeDictionary LoadMimeTypes()
        {
            var mimeTypeDictionary = new MimeTypeDictionary();
            var entries            = new List <(string, string, string)>();

            foreach (var entry in GetMimeTypeEntries())
            {
                var match = MimetypesLineRegex.Match(entry);

                if (!match.Success)
                {
                    continue;
                }

                var type      = match.Groups[1].Value;
                var subtype   = match.Groups[2].Value;
                var extension = match.Groups[3].Value;

                entries.Add((type, subtype, extension));

                mimeTypeDictionary.Add(type, subtype, extension);
            }

            return(mimeTypeDictionary);
        }
        public string GenerateMimeTypeGroups(MimeTypeDictionary mimeTypeDictionary)
        {
            var sourceCodeBuilder = new StringBuilder();

            foreach (var mimeGroup in mimeTypeDictionary.All())
            {
                sourceCodeBuilder.AppendLine(GetMimeTypePartialClassSouceCode(mimeGroup));
            }

            return(FillOutMimeTypeGroupTemplate(sourceCodeBuilder.ToString()));
        }
        public string GenerateMimeTypeExtensions(MimeTypeDictionary mimeTypeDictionary)
        {
            var subtypeSourceCode = new StringBuilder();

            foreach (var group in mimeTypeDictionary.All())
            {
                foreach (var subType in group.All())
                {
                    var extensions = string.Join(",", subType.All().Select(e => $"\"{e}\""));
                    subtypeSourceCode.AppendLine(
                        $"            {{{subType.LegalTypeName}.{subType.LegalSubTypeName}, new HashSet<string>(){{{extensions}}}}},");
                }
            }

            return(FillOutMimeTypeExtensionTemplate(subtypeSourceCode.ToString()));
        }