Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
pluginbase.Helpers.BinaryCodecs.Providers.ComplexBsonCodecProvider Class Reference
Inheritance diagram for pluginbase.Helpers.BinaryCodecs.Providers.ComplexBsonCodecProvider:
pluginbase.Helpers.BinaryCodecs.IBinaryCodec

Public Member Functions

 ComplexBsonCodecProvider ()
 
TypeCodec GetCodec (Type type)
 

Constructor & Destructor Documentation

pluginbase.Helpers.BinaryCodecs.Providers.ComplexBsonCodecProvider.ComplexBsonCodecProvider ( )
13  {
14  _serializer = new JsonSerializer();
15  _serializer.TypeNameHandling = TypeNameHandling.Auto;
16  _serializer.ContractResolver = ComplexBsonFieldResolver.Instance;
17  }

Member Function Documentation

TypeCodec pluginbase.Helpers.BinaryCodecs.Providers.ComplexBsonCodecProvider.GetCodec ( Type  type)

Implements pluginbase.Helpers.BinaryCodecs.IBinaryCodec.

20  {
21  if (type.IsArray || typeof(IList).IsAssignableFrom(type))
22  {
23  return new TypeCodec
24  {
25  Decode = r => {
26  var bson = new BsonReader(r, true, new DateTimeKind());
27  return _serializer.Deserialize(bson, type);
28  },
29  Encode = (w,v) => {
30  var bson = new BsonWriter(w);
31  _serializer.Serialize(bson, v);
32  }
33  };
34  }
35 
36  if (type.IsClass || (type.IsValueType && !type.IsEnum && !type.IsPrimitive))
37  {
38  //Class or basic struct
39  return new TypeCodec
40  {
41  Decode = r => {
42  var bson = new BsonReader(r);
43  return _serializer.Deserialize(bson, type);
44  },
45  Encode = (w,v) => {
46  var bson = new BsonWriter(w);
47  _serializer.Serialize(bson, v);
48  }
49  };
50  }
51  return null;
52  }

The documentation for this class was generated from the following file: