aboutsummaryrefslogtreecommitdiffstats
path: root/src/IOL.Helpers
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2021-04-23 23:10:26 +0200
committerivarlovlie <git@ivarlovlie.no>2021-04-23 23:10:26 +0200
commit8cbf8cbc9f450db8f3422cae610289effc6d1c1f (patch)
tree085f982915091ca9af44f273505be617da5ea342 /src/IOL.Helpers
parentf227d1c15e619eb3d7b44e1475a223513489d2d3 (diff)
downloaddotnet-helpers-8cbf8cbc9f450db8f3422cae610289effc6d1c1f.tar.xz
dotnet-helpers-8cbf8cbc9f450db8f3422cae610289effc6d1c1f.zip
Add UnicornFormat
Diffstat (limited to 'src/IOL.Helpers')
-rw-r--r--src/IOL.Helpers/IOL.Helpers.csproj4
-rw-r--r--src/IOL.Helpers/StringHelpers.cs28
2 files changed, 27 insertions, 5 deletions
diff --git a/src/IOL.Helpers/IOL.Helpers.csproj b/src/IOL.Helpers/IOL.Helpers.csproj
index dcdf4cf..63772ad 100644
--- a/src/IOL.Helpers/IOL.Helpers.csproj
+++ b/src/IOL.Helpers/IOL.Helpers.csproj
@@ -17,8 +17,10 @@ Add optional parameter to skip X-Forwarded-Host and X-Forwarded-Proto</PackageRe
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="5.0.4" />
+ <PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="5.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
+ <PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
+ <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
</ItemGroup>
</Project>
diff --git a/src/IOL.Helpers/StringHelpers.cs b/src/IOL.Helpers/StringHelpers.cs
index 1dde161..c090117 100644
--- a/src/IOL.Helpers/StringHelpers.cs
+++ b/src/IOL.Helpers/StringHelpers.cs
@@ -1,6 +1,9 @@
using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
+using Microsoft.Extensions.Configuration;
namespace IOL.Helpers
{
@@ -18,6 +21,23 @@ namespace IOL.Helpers
return !value.IsNullOrWhiteSpace();
}
+ public static string UnicornFormat(this string input, IDictionary<string, string> values) {
+ if (string.IsNullOrWhiteSpace(input)) return default;
+ return values.Count == 0 ? default : values.Aggregate(input, (current, value1) => current.Replace("{" + value1.Key + "}", value1.Value));
+ }
+
+
+ public static string UnicornFormatWithEnvironment(this string input, IConfiguration configuration) {
+ if (string.IsNullOrWhiteSpace(input)) return default;
+ var matchList = Regex.Matches(input, "");
+ foreach (var key in matchList.Select(match => match.Value)) {
+ var value = configuration.GetValue<string>(key);
+ input = input.Replace(key, value);
+ }
+
+ return input;
+ }
+
public static Guid ToGuid(this string value) {
return Guid.Parse(value);
}
@@ -29,7 +49,7 @@ namespace IOL.Helpers
public static string ExtractFileName(this string value) {
if (value.IsNullOrWhiteSpace()) return default;
var lastIndex = value.LastIndexOf('.');
- return lastIndex <= 0 ? default : value.Substring(0, lastIndex);
+ return lastIndex <= 0 ? default : value[..lastIndex];
}
public static string ExtractExtension(this string value) {
@@ -40,8 +60,8 @@ namespace IOL.Helpers
public static string Capitalize(this string input) {
return input.IsNullOrWhiteSpace()
- ? input
- : Regex.Replace(input, @"\b(\w)", m => m.Value.ToUpper(), RegexOptions.None);
+ ? input
+ : Regex.Replace(input, @"\b(\w)", m => m.Value.ToUpper(), RegexOptions.None);
}
@@ -64,4 +84,4 @@ namespace IOL.Helpers
return "****" + last4Chars;
}
}
-} \ No newline at end of file
+}