ZeroInstall.Publish.Capture.SnapshotDiff.AddExtensionToFileType C# (CSharp) Method

AddExtensionToFileType() private static method

Adds an extension to an existing FileType.
private static AddExtensionToFileType ( [ extension, [ progID, [ capabilities ) : void
extension [ The file extension including the leading dot (e.g. ".png").
progID [ The ID of the to add the extension to.
capabilities [ The list of capabilities to find existing s in.
return void
        private static void AddExtensionToFileType([NotNull] string extension, [NotNull] string progID, [NotNull] CapabilityList capabilities)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(progID)) throw new ArgumentNullException(nameof(progID));
            if (string.IsNullOrEmpty(extension)) throw new ArgumentNullException(nameof(extension));
            if (capabilities == null) throw new ArgumentNullException(nameof(capabilities));
            #endregion

            // Find the matching existing file type
            var fileType = capabilities.Entries.OfType<FileType>().FirstOrDefault(type => type.ID == progID);

            if (fileType != null)
            {
                // Check if the file type already has the extension and add it if not
                if (!fileType.Extensions.Any(element => StringUtils.EqualsIgnoreCase(element.Value, extension)))
                    fileType.Extensions.Add(new FileTypeExtension {Value = extension.ToLower()});
            }
        }
        #endregion