fix
This commit is contained in:
@@ -24,6 +24,26 @@ public static class StringExtensions
|
||||
return str != null && str.Equals(value, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public static string? SafeTrim(this string? str)
|
||||
{
|
||||
return str == null ? str : str!.Trim();
|
||||
}
|
||||
|
||||
public static string? MaxOf(this string? str, int maxLength)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (str.Length < maxLength)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
return str.Substring(0, maxLength);
|
||||
}
|
||||
|
||||
public static bool AsBool(this string? str, bool defaultValue = false)
|
||||
{
|
||||
return true.ToString().Equals(str, StringComparison.OrdinalIgnoreCase) || defaultValue;
|
||||
@@ -31,21 +51,11 @@ public static class StringExtensions
|
||||
|
||||
public static Guid AsGuid(this string str)
|
||||
{
|
||||
/*str = str
|
||||
.Replace("_", "/")
|
||||
.Replace("-", "+");
|
||||
byte[] buffer = Convert.FromBase64String(str + "==");
|
||||
return new Guid(buffer);*/
|
||||
return Guid.Parse(str);
|
||||
}
|
||||
|
||||
public static Guid? AsGuidNull(this string str)
|
||||
{
|
||||
/*str = str
|
||||
.Replace("_", "/")
|
||||
.Replace("-", "+");
|
||||
byte[] buffer = Convert.FromBase64String(str + "==");
|
||||
return new Guid(buffer);*/
|
||||
if (Guid.TryParse(str, out var guid))
|
||||
{
|
||||
return guid;
|
||||
|
||||
Reference in New Issue
Block a user