1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
/// <summary>
/// Provides helper overloads to a <see cref = "Configuration" />.
/// </summary>
public static class ConfigurationExtensions
{
/// <summary>
/// Get a configuration value for the given key parts.
/// <para>
/// For example in order to get the value for this in a .git\config file:
///
/// <code>
/// [core]
/// bare = true
/// </code>
///
/// You would call:
///
/// <code>
/// bool isBare = repo.Config.Get<bool>(new []{ "core", "bare" }).Value;
/// </code>
/// </para>
/// </summary>
/// <typeparam name = "T">The configuration value type</typeparam>
/// <param name = "config">The configuration being worked with.</param>
/// <param name = "keyParts">The key parts</param>
/// <returns>The <see cref="ConfigurationEntry{T}"/>, or null if not set</returns>
public static ConfigurationEntry<T> Get<T>(this Configuration config, string[] keyParts)
{
Ensure.ArgumentNotNull(keyParts, "keyParts");
return config.Get<T>(string.Join(".", keyParts));
}
/// <summary>
/// Get a configuration value for the given key parts.
/// <para>
/// For example in order to get the value for this in a .git\config file:
///
/// <code>
/// [difftool "kdiff3"]
/// path = c:/Program Files/KDiff3/kdiff3.exe
/// </code>
///
/// You would call:
///
/// <code>
/// string where = repo.Config.Get<string>("difftool", "kdiff3", "path").Value;
/// </code>
/// </para>
/// </summary>
/// <typeparam name = "T">The configuration value type</typeparam>
/// <param name = "config">The configuration being worked with.</param>
/// <param name = "firstKeyPart">The first key part</param>
/// <param name = "secondKeyPart">The second key part</param>
/// <param name = "thirdKeyPart">The third key part</param>
/// <returns>The <see cref="ConfigurationEntry{T}"/>, or null if not set</returns>
public static ConfigurationEntry<T> Get<T>(this Configuration config, string firstKeyPart, string secondKeyPart, string thirdKeyPart)
{
Ensure.ArgumentNotNullOrEmptyString(firstKeyPart, "firstKeyPart");
Ensure.ArgumentNotNullOrEmptyString(secondKeyPart, "secondKeyPart");
Ensure.ArgumentNotNullOrEmptyString(thirdKeyPart, "secondKeyPart");
return config.Get<T>(new[] { firstKeyPart, secondKeyPart, thirdKeyPart });
}
}
}
|