0 people like it.
Like the snippet!
mongodb - map immutable record constructor - adhoc example
adhoc example
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
|
open System
open System.Reflection
open MongoDB.Bson
open MongoDB.Bson.Serialization
open MongoDB.Bson.Serialization.Serializers
open MongoDB.Driver
open MongoDB.Driver.Core
type YourImmutableRecord = { id : Guid; text : string }
let ctor = (typeof<YourImmutableRecord >).GetConstructors().[0]
let map (a : BsonClassMap<YourImmutableRecord>) =
a.AutoMap()
a.MapIdMember(fun (a) -> a.id).SetSerializer(new GuidSerializer(BsonType.String)) |> ignore
a.MapProperty(fun (a) -> a.text) |> ignore
a.MapConstructor(ctor, ctor.GetParameters() |> Array.map (fun (a) -> a.Name)) |> ignore
let mapper = Action<_>(fun (a : BsonClassMap<YourImmutableRecord>) -> map a)
BsonClassMap.RegisterClassMap<YourImmutableRecord> mapper |> ignore
|
namespace System
namespace System.Reflection
namespace MongoDB
namespace MongoDB.Bson
namespace MongoDB.Bson.Serialization
namespace MongoDB.Bson.Serialization.Serializers
namespace MongoDB.Driver
namespace MongoDB.Driver.Core
type YourImmutableRecord =
{id: Guid;
text: string;}
Full name: Script.YourImmutableRecord
YourImmutableRecord.id: Guid
Multiple items
type Guid =
struct
new : b:byte[] -> Guid + 4 overloads
member CompareTo : value:obj -> int + 1 overload
member Equals : o:obj -> bool + 1 overload
member GetHashCode : unit -> int
member ToByteArray : unit -> byte[]
member ToString : unit -> string + 2 overloads
static val Empty : Guid
static member NewGuid : unit -> Guid
static member Parse : input:string -> Guid
static member ParseExact : input:string * format:string -> Guid
...
end
Full name: System.Guid
--------------------
Guid()
Guid(b: byte []) : unit
Guid(g: string) : unit
Guid(a: int, b: int16, c: int16, d: byte []) : unit
Guid(a: uint32, b: uint16, c: uint16, d: byte, e: byte, f: byte, g: byte, h: byte, i: byte, j: byte, k: byte) : unit
Guid(a: int, b: int16, c: int16, d: byte, e: byte, f: byte, g: byte, h: byte, i: byte, j: byte, k: byte) : unit
YourImmutableRecord.text: string
Multiple items
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = String
Full name: Microsoft.FSharp.Core.string
val ctor : ConstructorInfo
Full name: Script.ctor
val typeof<'T> : Type
Full name: Microsoft.FSharp.Core.Operators.typeof
val map : a:BsonClassMap<YourImmutableRecord> -> unit
Full name: Script.map
val a : BsonClassMap<YourImmutableRecord>
Multiple items
type BsonClassMap =
new : classType:Type -> BsonClassMap + 1 overload
member AddKnownType : type:Type -> unit
member AllMemberMaps : ReadOnlyCollection<BsonMemberMap>
member AutoMap : unit -> unit
member BaseClassMap : BsonClassMap
member ClassType : Type
member ConventionPack : IConventionPack
member CreateInstance : unit -> obj
member CreatorMaps : IEnumerable<BsonCreatorMap>
member DeclaredMemberMaps : IEnumerable<BsonMemberMap>
...
Full name: MongoDB.Bson.Serialization.BsonClassMap
--------------------
type BsonClassMap<'TClass> =
inherit BsonClassMap
new : unit -> BsonClassMap<'TClass> + 1 overload
member CreateInstance : unit -> 'TClass
member GetMemberMap<'TMember> : memberLambda:Expression<Func<'TClass, 'TMember>> -> BsonMemberMap
member MapCreator : creatorLambda:Expression<Func<'TClass, 'TClass>> -> BsonCreatorMap
member MapExtraElementsField<'TMember> : fieldLambda:Expression<Func<'TClass, 'TMember>> -> BsonMemberMap
member MapExtraElementsMember<'TMember> : memberLambda:Expression<Func<'TClass, 'TMember>> -> BsonMemberMap
member MapExtraElementsProperty<'TMember> : propertyLambda:Expression<Func<'TClass, 'TMember>> -> BsonMemberMap
member MapField<'TMember> : fieldLambda:Expression<Func<'TClass, 'TMember>> -> BsonMemberMap
member MapIdField<'TMember> : fieldLambda:Expression<Func<'TClass, 'TMember>> -> BsonMemberMap
member MapIdMember<'TMember> : memberLambda:Expression<Func<'TClass, 'TMember>> -> BsonMemberMap
...
Full name: MongoDB.Bson.Serialization.BsonClassMap<_>
--------------------
BsonClassMap(classType: Type) : unit
BsonClassMap(classType: Type, baseClassMap: BsonClassMap) : unit
--------------------
BsonClassMap() : unit
BsonClassMap(classMapInitializer: Action<BsonClassMap<'TClass>>) : unit
BsonClassMap.AutoMap() : unit
BsonClassMap.MapIdMember(memberInfo: MemberInfo) : BsonMemberMap
BsonClassMap.MapIdMember<'TMember>(memberLambda: Linq.Expressions.Expression<Func<YourImmutableRecord,'TMember>>) : BsonMemberMap
val a : YourImmutableRecord
Multiple items
type GuidSerializer =
inherit StructSerializerBase<Guid>
new : unit -> GuidSerializer + 1 overload
member Deserialize : context:BsonDeserializationContext * args:BsonDeserializationArgs -> Guid
member Representation : BsonType
member Serialize : context:BsonSerializationContext * args:BsonSerializationArgs * value:Guid -> unit
member WithRepresentation : representation:BsonType -> GuidSerializer
Full name: MongoDB.Bson.Serialization.Serializers.GuidSerializer
--------------------
GuidSerializer() : unit
GuidSerializer(representation: BsonType) : unit
type BsonType =
| EndOfDocument = 0
| Double = 1
| String = 2
| Document = 3
| Array = 4
| Binary = 5
| Undefined = 6
| ObjectId = 7
| Boolean = 8
| DateTime = 9
...
Full name: MongoDB.Bson.BsonType
field BsonType.String = 2
val ignore : value:'T -> unit
Full name: Microsoft.FSharp.Core.Operators.ignore
MethodBase.GetParameters() : ParameterInfo []
type Array =
member Clone : unit -> obj
member CopyTo : array:Array * index:int -> unit + 1 overload
member GetEnumerator : unit -> IEnumerator
member GetLength : dimension:int -> int
member GetLongLength : dimension:int -> int64
member GetLowerBound : dimension:int -> int
member GetUpperBound : dimension:int -> int
member GetValue : [<ParamArray>] indices:int[] -> obj + 7 overloads
member Initialize : unit -> unit
member IsFixedSize : bool
...
Full name: System.Array
val map : mapping:('T -> 'U) -> array:'T [] -> 'U []
Full name: Microsoft.FSharp.Collections.Array.map
val a : ParameterInfo
property ParameterInfo.Name: string
val mapper : Action<BsonClassMap<YourImmutableRecord>>
Full name: Script.mapper
Multiple items
type Action =
delegate of unit -> unit
Full name: System.Action
--------------------
type Action<'T> =
delegate of 'T -> unit
Full name: System.Action<_>
--------------------
type Action<'T1,'T2> =
delegate of 'T1 * 'T2 -> unit
Full name: System.Action<_,_>
--------------------
type Action<'T1,'T2,'T3> =
delegate of 'T1 * 'T2 * 'T3 -> unit
Full name: System.Action<_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 -> unit
Full name: System.Action<_,_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4,'T5> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 -> unit
Full name: System.Action<_,_,_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4,'T5,'T6> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 -> unit
Full name: System.Action<_,_,_,_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4,'T5,'T6,'T7> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 -> unit
Full name: System.Action<_,_,_,_,_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 -> unit
Full name: System.Action<_,_,_,_,_,_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 -> unit
Full name: System.Action<_,_,_,_,_,_,_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 -> unit
Full name: System.Action<_,_,_,_,_,_,_,_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 -> unit
Full name: System.Action<_,_,_,_,_,_,_,_,_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 -> unit
Full name: System.Action<_,_,_,_,_,_,_,_,_,_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'T13> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 * 'T13 -> unit
Full name: System.Action<_,_,_,_,_,_,_,_,_,_,_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'T13,'T14> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 * 'T13 * 'T14 -> unit
Full name: System.Action<_,_,_,_,_,_,_,_,_,_,_,_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'T13,'T14,'T15> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 * 'T13 * 'T14 * 'T15 -> unit
Full name: System.Action<_,_,_,_,_,_,_,_,_,_,_,_,_,_,_>
--------------------
type Action<'T1,'T2,'T3,'T4,'T5,'T6,'T7,'T8,'T9,'T10,'T11,'T12,'T13,'T14,'T15,'T16> =
delegate of 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'T8 * 'T9 * 'T10 * 'T11 * 'T12 * 'T13 * 'T14 * 'T15 * 'T16 -> unit
Full name: System.Action<_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_>
BsonClassMap.RegisterClassMap<'TClass>() : BsonClassMap<'TClass>
BsonClassMap.RegisterClassMap(classMap: BsonClassMap) : unit
BsonClassMap.RegisterClassMap<'TClass>(classMapInitializer: Action<BsonClassMap<'TClass>>) : BsonClassMap<'TClass>
More information