internal static void SetupProtocolProviders(List <IProtocolProvider> protocolProviders)
 {
     ProtocolProviders = new Dictionary <string, CachedProtocolProvider>(StringComparer.OrdinalIgnoreCase);
     protocolProviders = protocolProviders ?? new List <IProtocolProvider>();
     protocolProviders.Add(new DefaultProtocolProvider());
     protocolProviders.ForEach(provider =>
     {
         ValidateProtocolProvider(provider);
         var cachedProvider = GetCachedProtocolProvider(provider);
         if (provider is DefaultProtocolProvider)
         {
             DefaultProtocolProvider = cachedProvider;
             ProtocolProviders[""]   = cachedProvider;
         }
         var protocolId = provider.ProtocolIdentifier;
         if (ProtocolProviders.TryGetValue(protocolId, out var existing))
         {
             if (existing.GetType() == provider.GetType())
             {
                 throw new InvalidProtocolProviderException(
                     $"A protocol provider of type '{existing.GetType()}' has already been added");
             }
             throw new InvalidProtocolProviderException(
                 $"Protocol identifier '{protocolId}' already claimed by a protocol provider of type '{existing.GetType()}'");
         }
         ProtocolProviders[protocolId] = cachedProvider;
     });
 }
        private static CachedProtocolProvider GetCachedProtocolProvider(IProtocolProvider provider)
        {
            var cProvider            = new CachedProtocolProvider(provider);
            var contentTypeProviders = provider.GetContentTypeProviders()?.ToList();

            contentTypeProviders?.ForEach(contentTypeProvider =>
            {
                if (contentTypeProvider.CanRead)
                {
                    contentTypeProvider.MatchStrings?.ForEach(mimeType => cProvider.InputMimeBindings[mimeType] = contentTypeProvider);
                }
                if (contentTypeProvider.CanWrite)
                {
                    contentTypeProvider.MatchStrings?.ForEach(mimeType => cProvider.OutputMimeBindings[mimeType] = contentTypeProvider);
                }
            });
            switch (provider.ExternalContentTypeProviderSettings)
            {
            case ExternalContentTypeProviderSettings.AllowAll:
                ContentTypeController.InputContentTypeProviders.Where(p => !cProvider.InputMimeBindings.ContainsKey(p.Key))
                .ForEach(cProvider.InputMimeBindings.Add);
                ContentTypeController.OutputContentTypeProviders.Where(p => !cProvider.OutputMimeBindings.ContainsKey(p.Key))
                .ForEach(cProvider.OutputMimeBindings.Add);
                break;

            case ExternalContentTypeProviderSettings.AllowInput:
                ContentTypeController.InputContentTypeProviders.Where(p => !cProvider.InputMimeBindings.ContainsKey(p.Key))
                .ForEach(cProvider.InputMimeBindings.Add);
                break;

            case ExternalContentTypeProviderSettings.AllowOutput:
                ContentTypeController.OutputContentTypeProviders.Where(p => !cProvider.OutputMimeBindings.ContainsKey(p.Key))
                .ForEach(cProvider.OutputMimeBindings.Add);
                break;
            }
            return(cProvider);
        }