Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4277559

Browse files
shiftkeynulltoken
authored andcommitted
Drop optional parameters in ConfigurationExtensions.cs
1 parent 631b36c commit 4277559

File tree

1 file changed

+59
-8
lines changed

1 file changed

+59
-8
lines changed

LibGit2Sharp/ConfigurationExtensions.cs

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ public static ConfigurationEntry<T> Get<T>(this Configuration config, string fir
6868
return config.Get<T>(new[] { firstKeyPart, secondKeyPart, thirdKeyPart });
6969
}
7070

71+
/// <summary>
72+
/// Get a configuration value for the given key.
73+
/// </summary>
74+
/// <typeparam name="T">The configuration value type.</typeparam>
75+
/// <param name="config">The configuration being worked with.</param>
76+
/// <param name="key">The key</param>
77+
/// <returns>The configuration value, or the default value for the selected <see typeparamref="T"/>if not found</returns>
78+
public static T GetValueOrDefault<T>(this Configuration config, string key)
79+
{
80+
return ValueOrDefault(config.Get<T>(key), default(T));
81+
}
82+
7183
/// <summary>
7284
/// Get a configuration value for the given key,
7385
/// or <paramref name="defaultValue" /> if the key is not set.
@@ -76,27 +88,52 @@ public static ConfigurationEntry<T> Get<T>(this Configuration config, string fir
7688
/// <param name="config">The configuration being worked with.</param>
7789
/// <param name="key">The key</param>
7890
/// <param name="defaultValue">The default value if the key is not set.</param>
79-
/// <returns>The configuration value, or the default.</returns>
80-
public static T GetValueOrDefault<T>(this Configuration config, string key, T defaultValue = default(T))
91+
/// <returns>The configuration value, or the default value</returns>
92+
public static T GetValueOrDefault<T>(this Configuration config, string key, T defaultValue)
8193
{
8294
return ValueOrDefault(config.Get<T>(key), defaultValue);
8395
}
8496

97+
/// <summary>
98+
/// Get a configuration value for the given key
99+
/// </summary>
100+
/// <typeparam name="T">The configuration value type.</typeparam>
101+
/// <param name="config">The configuration being worked with.</param>
102+
/// <param name="key">The key.</param>
103+
/// <param name="level">The configuration file into which the key should be searched for.</param>
104+
/// <returns>The configuration value, or the default value for <see typeparamref="T"/> if not found</returns>
105+
public static T GetValueOrDefault<T>(this Configuration config, string key, ConfigurationLevel level)
106+
{
107+
return ValueOrDefault(config.Get<T>(key, level), default(T));
108+
}
109+
85110
/// <summary>
86111
/// Get a configuration value for the given key,
87112
/// or <paramref name="defaultValue" /> if the key is not set.
88113
/// </summary>
89114
/// <typeparam name="T">The configuration value type.</typeparam>
90-
/// <param name="config">The configuration being worked with.</param>
115+
/// <param name="config">The configuration being worked with.</param>
91116
/// <param name="key">The key.</param>
92117
/// <param name="level">The configuration file into which the key should be searched for.</param>
93118
/// <param name="defaultValue">The selector used to generate a default value if the key is not set.</param>
94-
/// <returns>The configuration value, or the default.</returns>
95-
public static T GetValueOrDefault<T>(this Configuration config, string key, ConfigurationLevel level, T defaultValue = default(T))
119+
/// <returns>The configuration value, or the default value.</returns>
120+
public static T GetValueOrDefault<T>(this Configuration config, string key, ConfigurationLevel level, T defaultValue)
96121
{
97122
return ValueOrDefault(config.Get<T>(key, level), defaultValue);
98123
}
99124

125+
/// <summary>
126+
/// Get a configuration value for the given key parts
127+
/// </summary>
128+
/// <typeparam name="T">The configuration value type.</typeparam>
129+
/// <param name="config">The configuration being worked with.</param>
130+
/// <param name="keyParts">The key parts.</param>
131+
/// <returns>The configuration value, or the default value for<see typeparamref="T"/> if not found</returns>
132+
public static T GetValueOrDefault<T>(this Configuration config, string[] keyParts)
133+
{
134+
return ValueOrDefault(config.Get<T>(keyParts), default(T));
135+
}
136+
100137
/// <summary>
101138
/// Get a configuration value for the given key parts,
102139
/// or <paramref name="defaultValue" /> if the key is not set.
@@ -105,12 +142,26 @@ public static ConfigurationEntry<T> Get<T>(this Configuration config, string fir
105142
/// <param name="config">The configuration being worked with.</param>
106143
/// <param name="keyParts">The key parts.</param>
107144
/// <param name="defaultValue">The default value if the key is not set.</param>
108-
/// <returns>The configuration value, or the default.</returns>
109-
public static T GetValueOrDefault<T>(this Configuration config, string[] keyParts, T defaultValue = default(T))
145+
/// <returns>The configuration value, or the default value.</returns>
146+
public static T GetValueOrDefault<T>(this Configuration config, string[] keyParts, T defaultValue)
110147
{
111148
return ValueOrDefault(config.Get<T>(keyParts), defaultValue);
112149
}
113150

151+
/// <summary>
152+
/// Get a configuration value for the given key parts.
153+
/// </summary>
154+
/// <typeparam name="T">The configuration value type.</typeparam>
155+
/// <param name="config">The configuration being worked with.</param>
156+
/// <param name="firstKeyPart">The first key part.</param>
157+
/// <param name="secondKeyPart">The second key part.</param>
158+
/// <param name="thirdKeyPart">The third key part.</param>
159+
/// <returns>The configuration value, or the default value for the selected <see typeparamref="T"/> if not found</returns>
160+
public static T GetValueOrDefault<T>(this Configuration config, string firstKeyPart, string secondKeyPart, string thirdKeyPart)
161+
{
162+
return ValueOrDefault(config.Get<T>(firstKeyPart, secondKeyPart, thirdKeyPart), default(T));
163+
}
164+
114165
/// <summary>
115166
/// Get a configuration value for the given key parts,
116167
/// or <paramref name="defaultValue" /> if the key is not set.
@@ -122,7 +173,7 @@ public static ConfigurationEntry<T> Get<T>(this Configuration config, string fir
122173
/// <param name="thirdKeyPart">The third key part.</param>
123174
/// <param name="defaultValue">The default value if the key is not set.</param>
124175
/// <returns>The configuration value, or the default.</returns>
125-
public static T GetValueOrDefault<T>(this Configuration config, string firstKeyPart, string secondKeyPart, string thirdKeyPart, T defaultValue = default(T))
176+
public static T GetValueOrDefault<T>(this Configuration config, string firstKeyPart, string secondKeyPart, string thirdKeyPart, T defaultValue)
126177
{
127178
return ValueOrDefault(config.Get<T>(firstKeyPart, secondKeyPart, thirdKeyPart), defaultValue);
128179
}

0 commit comments

Comments
 (0)