aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-01-28 20:56:37 +0100
committerivarlovlie <git@ivarlovlie.no>2022-01-28 20:56:37 +0100
commitc925e86c9c56f7f23e7f12685ae3213eb701fcce (patch)
treeea06917bbce2f2f5a3521d601f5c284526d9fad8 /src
parentbb48c7df9c6cd7e7a4e8907cc312980def1ab166 (diff)
downloaddotnet-helpers-c925e86c9c56f7f23e7f12685ae3213eb701fcce.tar.xz
dotnet-helpers-c925e86c9c56f7f23e7f12685ae3213eb701fcce.zip
feat!: ToGuid now throws on non-guid strings
Added ToGuidOrDefault for old behaviour
Diffstat (limited to 'src')
-rw-r--r--src/IOL.Helpers/CryptographyHelpers.cs1
-rw-r--r--src/IOL.Helpers/IOL.Helpers.csproj8
-rw-r--r--src/IOL.Helpers/StringHelpers.cs9
3 files changed, 12 insertions, 6 deletions
diff --git a/src/IOL.Helpers/CryptographyHelpers.cs b/src/IOL.Helpers/CryptographyHelpers.cs
index 4821613..df53055 100644
--- a/src/IOL.Helpers/CryptographyHelpers.cs
+++ b/src/IOL.Helpers/CryptographyHelpers.cs
@@ -155,7 +155,6 @@ public static class CryptographyHelpers
return Convert.ToBase64String(hash);
}
-
/// <summary>
/// Creates a SHA256 hash of the specified input.
/// </summary>
diff --git a/src/IOL.Helpers/IOL.Helpers.csproj b/src/IOL.Helpers/IOL.Helpers.csproj
index 2bd3b45..2310989 100644
--- a/src/IOL.Helpers/IOL.Helpers.csproj
+++ b/src/IOL.Helpers/IOL.Helpers.csproj
@@ -19,10 +19,10 @@
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="6.0.0"/>
- <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0"/>
- <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0"/>
- <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0"/>
+ <PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="6.0.1" />
+ <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
+ <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
+ <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
</ItemGroup>
</Project>
diff --git a/src/IOL.Helpers/StringHelpers.cs b/src/IOL.Helpers/StringHelpers.cs
index 783d238..366ca00 100644
--- a/src/IOL.Helpers/StringHelpers.cs
+++ b/src/IOL.Helpers/StringHelpers.cs
@@ -17,6 +17,10 @@ public static class StringHelpers
return Slug.Generate(true, input);
}
+ public static string ToSnakeCase(this string str) {
+ return string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x : x.ToString())).ToLower();
+ }
+
public static bool HasValue(this string value) {
return !value.IsNullOrWhiteSpace();
}
@@ -26,7 +30,6 @@ public static class StringHelpers
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, "{[a-z|_]*}", RegexOptions.IgnoreCase);
@@ -40,6 +43,10 @@ public static class StringHelpers
}
public static Guid ToGuid(this string value) {
+ return new Guid(value);
+ }
+
+ public static Guid ToGuidOrDefault(this string value) {
return !Guid.TryParse(value, out var res) ? default : res;
}