浏览代码

Parse config value correctly

Mark Monteiro 5 年之前
父节点
当前提交
d437950ac3

+ 1 - 16
MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs

@@ -31,7 +31,7 @@ namespace MediaBrowser.Controller.Extensions
         /// <returns>The parsed config value.</returns>
         /// <exception cref="FormatException">The config value is not a valid bool string. See <see cref="bool.Parse(string)"/>.</exception>
         public static bool IsNoWebContent(this IConfiguration configuration)
-            => configuration.ParseBoolean(NoWebContentKey);
+            => configuration.GetValue<bool>(NoWebContentKey);
 
         /// <summary>
         /// Retrieves the FFmpeg probe size from the <see cref="IConfiguration" />.
@@ -48,20 +48,5 @@ namespace MediaBrowser.Controller.Extensions
         /// <returns>The FFmpeg analyse duration option.</returns>
         public static string GetFFmpegAnalyzeDuration(this IConfiguration configuration)
             => configuration[FfmpegAnalyzeDurationKey];
-
-        /// <summary>
-        /// Convert the specified configuration string value its <see cref="bool"/> equivalent.
-        /// </summary>
-        /// <param name="configuration">The configuration to retrieve and parse the setting from.</param>
-        /// <param name="key">The key to use to retrieve the string value from the configuration.</param>
-        /// <returns>The parsed boolean value.</returns>
-        /// <exception cref="FormatException">The config value is not a valid bool string. See <see cref="bool.Parse(string)"/>.</exception>
-        public static bool ParseBoolean(this IConfiguration configuration, string key)
-        {
-            string configValue = configuration[key];
-            return bool.TryParse(configValue, out bool result) ?
-                result :
-                throw new FormatException($"Invalid value for configuration option '{key}' (expected a boolean): {configValue}");
-        }
     }
 }

+ 1 - 0
MediaBrowser.Controller/MediaBrowser.Controller.csproj

@@ -9,6 +9,7 @@
 
   <ItemGroup>
     <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.1" />
+    <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.1" />
   </ItemGroup>
 
   <ItemGroup>