-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extensions.cs
31 lines (24 loc) · 986 Bytes
/
Extensions.cs
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
using System;
using Microsoft.Extensions.Configuration;
namespace PublisherNonBlocking {
/// <summary>
/// Extension methods for managing commandline parameters.
/// </summary>
internal static class Extensions {
internal static T GetEnum<T>(this IConfiguration config, string key, T value) {
T enumValue = config.GetValue<T>(key);
return (!Enum.Equals(enumValue, default(T))) ? enumValue : value;
}
internal static int GetInteger(this IConfiguration config, string key, int value) {
if (string.IsNullOrWhiteSpace(config[key])) {
return value;
} else {
return config.GetValue<int>(key);
}
}
internal static string GetString(this IConfiguration config, string key, string value) {
string token;
return !string.IsNullOrWhiteSpace(token = config.GetValue<string>(key)) ? token : value;
}
}
}