File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
src/CodeOfChaos.Extensions Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -29,18 +29,19 @@ public static bool IsNotNullOrWhiteSpace([NotNullWhen(true)] this string? str)
2929 public static string Truncate ( this string input , int maxLength )
3030 => input . Length <= maxLength ? input : input [ ..maxLength ] ;
3131
32- public static Guid ToGuid ( this string input ) {
33- #if DEBUG
34- if ( Guid . TryParse ( input , out Guid output ) ) return output ;
32+
33+ // Because "testing" of the value is handled by analyzer, we can just "blindly" parse during release.
34+ public static Guid ToGuid ( this string input )
35+ => Guid . Parse ( input ) ;
3536
36- Debug . Fail ( "Failed to parse Guid" ) ;
37+ public static Guid ToGuidOrDefault ( this string input ) {
38+ if ( Guid . TryParse ( input , out Guid guid ) ) return guid ;
3739 return Guid . Empty ;
38- #else
39- // Because "testing" of the value is handled by analyzer, we can just "blindly" parse during release.
40- return Guid . Parse ( input ) ;
41- #endif
4240 }
4341
42+ public static bool TryToGuid ( this string input , out Guid guid )
43+ => Guid . TryParse ( input , out guid ) ;
44+
4445 /// <summary>
4546 /// Converts a given string into a GUID by hashing it using the SHA256 algorithm.
4647 /// </summary>
You can’t perform that action at this time.
0 commit comments