Creado apartir del commit b888de6c92056de294456f581a56e25e734d4ab7 de develop
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using MongoDB.Bson;
|
||||
|
||||
namespace adas_core.Domain.Utils;
|
||||
|
||||
public static class BsonUtils
|
||||
{
|
||||
public static object? ToObject(this BsonValue val)
|
||||
{
|
||||
if (val.IsInt32) return val.AsInt32;
|
||||
|
||||
if (val.IsInt64) return val.AsInt64;
|
||||
|
||||
if (val.IsDouble) return val.AsDouble;
|
||||
|
||||
if (val.IsValidDateTime) return val.ToUniversalTime();
|
||||
|
||||
if (val.IsString) return val.AsString;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static BsonValue? Get(this BsonDocument doc, string key)
|
||||
{
|
||||
return doc.TryGetValue(key, out var value) ? value : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user