(refactor): removed uselss converters
This commit is contained in:
parent
318f2bf95c
commit
ab2d914c46
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<!-- NuGet package metadata -->
|
<!-- NuGet package metadata -->
|
||||||
<PackageId>MaksIT.MongoDB.Linq</PackageId>
|
<PackageId>MaksIT.MongoDB.Linq</PackageId>
|
||||||
<Version>1.0.9</Version>
|
<Version>1.1.0</Version>
|
||||||
<Authors>Maksym Sadovnychyy</Authors>
|
<Authors>Maksym Sadovnychyy</Authors>
|
||||||
<Company>MAKS-IT</Company>
|
<Company>MAKS-IT</Company>
|
||||||
<Product>MaksIT.MongoDB.Linq</Product>
|
<Product>MaksIT.MongoDB.Linq</Product>
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
using MongoDB.Bson;
|
|
||||||
using MongoDB.Bson.Serialization;
|
|
||||||
using MongoDB.Bson.Serialization.Serializers;
|
|
||||||
|
|
||||||
|
|
||||||
namespace MaksIT.MaksIT.MongoDB.Linq.Serializers;
|
|
||||||
|
|
||||||
public class GuidSerializer : SerializerBase<Guid> {
|
|
||||||
public override Guid Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) {
|
|
||||||
var bsonType = context.Reader.CurrentBsonType;
|
|
||||||
if (bsonType == BsonType.Binary) {
|
|
||||||
var binaryData = context.Reader.ReadBinaryData();
|
|
||||||
return new Guid(binaryData.Bytes);
|
|
||||||
}
|
|
||||||
throw new FormatException($"Cannot deserialize BsonType '{bsonType}' to Guid.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, Guid value) {
|
|
||||||
var guidBytes = value.ToByteArray();
|
|
||||||
var binaryData = new BsonBinaryData(guidBytes, BsonBinarySubType.UuidStandard);
|
|
||||||
context.Writer.WriteBinaryData(binaryData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
using MongoDB.Bson;
|
|
||||||
using MongoDB.Bson.Serialization;
|
|
||||||
using MongoDB.Bson.Serialization.Serializers;
|
|
||||||
|
|
||||||
|
|
||||||
namespace MaksIT.MaksIT.MongoDB.Linq.Serializers;
|
|
||||||
|
|
||||||
public class ListGuidSerializer : SerializerBase<List<Guid>> {
|
|
||||||
private readonly GuidSerializer _guidSerializer = new GuidSerializer();
|
|
||||||
|
|
||||||
public override List<Guid> Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) {
|
|
||||||
var bsonType = context.Reader.CurrentBsonType;
|
|
||||||
if (bsonType == BsonType.Array) {
|
|
||||||
var guidList = new List<Guid>();
|
|
||||||
context.Reader.ReadStartArray();
|
|
||||||
while (context.Reader.ReadBsonType() != BsonType.EndOfDocument) {
|
|
||||||
var guid = _guidSerializer.Deserialize(context, args);
|
|
||||||
guidList.Add(guid);
|
|
||||||
}
|
|
||||||
context.Reader.ReadEndArray();
|
|
||||||
return guidList;
|
|
||||||
}
|
|
||||||
throw new FormatException($"Cannot deserialize BsonType '{bsonType}' to List<Guid>.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, List<Guid> value) {
|
|
||||||
context.Writer.WriteStartArray();
|
|
||||||
foreach (var guid in value) {
|
|
||||||
_guidSerializer.Serialize(context, args, guid);
|
|
||||||
}
|
|
||||||
context.Writer.WriteEndArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user