fix
This commit is contained in:
@@ -6,4 +6,15 @@ public static class GuidExtensions
|
||||
{
|
||||
return guid.ToString().EqualsIgnoreCase(str);
|
||||
}
|
||||
|
||||
public static string ToShort(this Guid guid)
|
||||
{
|
||||
/*string encoded = Convert.ToBase64String(guid.ToByteArray());
|
||||
encoded = encoded
|
||||
.Replace("/", "_")
|
||||
.Replace("+", "-");
|
||||
|
||||
return encoded.Substring(0, 22);*/
|
||||
return guid.ToString("N");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
namespace MyOffice.Core.Extensions;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static bool IsMissing(this string? str)
|
||||
@@ -26,4 +28,28 @@ public static class StringExtensions
|
||||
{
|
||||
return true.ToString().Equals(str, StringComparison.OrdinalIgnoreCase) || defaultValue;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace MyOffice.Core.Helpers
|
||||
{
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
public static class JsonHelper
|
||||
{
|
||||
public static string ToJson(this object entity, JsonSerializerOptions? options = null)
|
||||
{
|
||||
options ??= new JsonSerializerOptions
|
||||
{
|
||||
MaxDepth = 0,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
ReferenceHandler = ReferenceHandler.IgnoreCycles,
|
||||
WriteIndented = true,
|
||||
};
|
||||
return JsonSerializer.Serialize(entity, options);
|
||||
}
|
||||
}
|
||||
|
||||
/*public class CustomIgnoreReferenceHandler : ReferenceHandler
|
||||
{
|
||||
//public CustomIgnoreReferenceHandler() => HandlingStrategy = ReferenceHandlingStrategy.IgnoreCycles;
|
||||
public CustomIgnoreReferenceHandler()
|
||||
{
|
||||
new HandlingStrategy { } = true;
|
||||
}
|
||||
|
||||
public override ReferenceResolver CreateResolver() => new IgnoreReferenceResolver();
|
||||
}*/
|
||||
}
|
||||
Reference in New Issue
Block a user