Last active
May 30, 2018 09:59
-
-
Save pietrom/496a4642f2f4006c500fbae39af196ba to your computer and use it in GitHub Desktop.
Custom mongodb serializer, able to wrap/unwrap string values to/from custom class instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClassSerializer : SerializerBase<Plate> { | |
public override MyClass Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) { | |
string value = context.Reader.ReadString(); | |
return new MyClass(value); | |
} | |
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, MyClass obj) { | |
context.Writer.WriteString(obj.Value); | |
} | |
} | |
class MyClass { | |
public string Value { get; } | |
public MyClass(string value) { | |
Value = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment