浏览代码

Add GetSetting shims

Bepis 5 年之前
父节点
当前提交
c5759cdccf
共有 1 个文件被更改,包括 34 次插入3 次删除
  1. 34 3
      BepInEx/Configuration/ConfigFile.cs

+ 34 - 3
BepInEx/Configuration/ConfigFile.cs

@@ -186,6 +186,37 @@ namespace BepInEx.Configuration
 		#region Wraps
 
 		/// <summary>
+		/// Access one of the existing settings. If the setting has not been added yet, null is returned.
+		/// If the setting exists but has a different type than T, an exception is thrown.
+		/// New settings should be added with <see cref="AddSetting{T}(ConfigDefinition,T,ConfigDescription)"/>.
+		/// </summary>
+		/// <typeparam name="T">Type of the value contained in this setting.</typeparam>
+		/// <param name="configDefinition">Section and Key of the setting.</param>
+		[Obsolete("Use ConfigFile[key] or TryGetEntry instead")]
+		public ConfigEntry<T> GetSetting<T>(ConfigDefinition configDefinition)
+		{
+			return TryGetEntry<T>(configDefinition, out var entry)
+				? entry
+				: null;
+		}
+
+		/// <summary>
+		/// Access one of the existing settings. If the setting has not been added yet, null is returned.
+		/// If the setting exists but has a different type than T, an exception is thrown.
+		/// New settings should be added with <see cref="AddSetting{T}(ConfigDefinition,T,ConfigDescription)"/>.
+		/// </summary>
+		/// <typeparam name="T">Type of the value contained in this setting.</typeparam>
+		/// <param name="section">Section/category/group of the setting. Settings are grouped by this.</param>
+		/// <param name="key">Name of the setting.</param>
+		[Obsolete("Use ConfigFile[key] or TryGetEntry instead")]
+		public ConfigEntry<T> GetSetting<T>(string section, string key)
+		{
+			return TryGetEntry<T>(section, key, out var entry)
+				? entry
+				: null;
+		}
+
+		/// <summary>
 		/// Access one of the existing settings. If the setting has not been added yet, false is returned. Otherwise, true.
 		/// If the setting exists but has a different type than T, an exception is thrown.
 		/// New settings should be added with <see cref="Bind{T}"/>.
@@ -289,7 +320,7 @@ namespace BepInEx.Configuration
 		/// <param name="configDefinition">Section and Key of the setting.</param>
 		/// <param name="defaultValue">Value of the setting if the setting was not created yet.</param>
 		/// <param name="configDescription">Description of the setting shown to the user and other metadata.</param>
-		[Obsolete("Use bind instead")]
+		[Obsolete("Use Bind instead")]
 		public ConfigEntry<T> AddSetting<T>(ConfigDefinition configDefinition, T defaultValue, ConfigDescription configDescription = null)
 			=> Bind(configDefinition, defaultValue, configDescription);
 
@@ -302,7 +333,7 @@ namespace BepInEx.Configuration
 		/// <param name="key">Name of the setting.</param>
 		/// <param name="defaultValue">Value of the setting if the setting was not created yet.</param>
 		/// <param name="configDescription">Description of the setting shown to the user and other metadata.</param>
-		[Obsolete("Use bind instead")]
+		[Obsolete("Use Bind instead")]
 		public ConfigEntry<T> AddSetting<T>(string section, string key, T defaultValue, ConfigDescription configDescription = null)
 			=> Bind(new ConfigDefinition(section, key), defaultValue, configDescription);
 
@@ -315,7 +346,7 @@ namespace BepInEx.Configuration
 		/// <param name="key">Name of the setting.</param>
 		/// <param name="defaultValue">Value of the setting if the setting was not created yet.</param>
 		/// <param name="description">Simple description of the setting shown to the user.</param>
-		[Obsolete("Use bind instead")]
+		[Obsolete("Use Bind instead")]
 		public ConfigEntry<T> AddSetting<T>(string section, string key, T defaultValue, string description)
 			=> Bind(new ConfigDefinition(section, key), defaultValue, new ConfigDescription(description));