diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-01-28 20:56:37 +0100 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-01-28 20:56:37 +0100 |
| commit | c925e86c9c56f7f23e7f12685ae3213eb701fcce (patch) | |
| tree | ea06917bbce2f2f5a3521d601f5c284526d9fad8 /src/IOL.Helpers/StringHelpers.cs | |
| parent | bb48c7df9c6cd7e7a4e8907cc312980def1ab166 (diff) | |
| download | dotnet-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/IOL.Helpers/StringHelpers.cs')
| -rw-r--r-- | src/IOL.Helpers/StringHelpers.cs | 9 |
1 files changed, 8 insertions, 1 deletions
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; } |
