-
Notifications
You must be signed in to change notification settings - Fork 0
/
Converters.fs
86 lines (69 loc) · 2.81 KB
/
Converters.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
module Transforms
open FSharp.Json
open System.Security.Cryptography
open System.Text.Json.Nodes
open Unions
open System
open System.Globalization
type OidConverter() =
interface ITypeTransform with
member _.targetType() = (fun _ -> typeof<Map<_, string>>)()
member _.fromTargetType (value: obj) =
(value :?>Map<_, string>)
|> Map.toSeq
|> Seq.exactlyOne
|> snd
|> string
|> fun x -> new Oid(x)
member _.toTargetType (value: obj) =
NotImplementedException()
type IntConverter() =
interface ITypeTransform with
member _.targetType() = (fun _ -> typeof<Map<string, string>>)()
member _.fromTargetType (value: obj) =
(value:?> Map<string, string>)
|> Map.toSeq
|> Seq.exactlyOne
|> snd
|> fun x -> Convert.ToInt32(x)
member _.toTargetType (value: obj) =
NotImplementedException()
type SByteConverter() =
interface ITypeTransform with
member _.targetType() = (fun _ -> typeof<Map<string, string>>)()
member _.fromTargetType (value: obj) =
(value:?> Map<string, string>)
|> Map.toSeq
|> Seq.exactlyOne
|> snd
|> fun x -> Convert.ToSByte(x)
member _.toTargetType (value: obj) =
NotImplementedException()
type DateConverter() =
interface ITypeTransform with
member _.targetType() = (fun _ -> typeof<Map<string, Map<string, string>>>)()
member _.fromTargetType (value: obj) =
(value:?> Map<string, Map<string, string>>)
|> Map.toSeq
|> Seq.exactlyOne
|> snd
|> Seq.exactlyOne
|> _.Value
|> fun x -> DateTimeOffset.FromUnixTimeMilliseconds(Int64.Parse(x)).DateTime
member _.toTargetType (value: obj) =
NotImplementedException()
type CategoryConverter() =
interface ITypeTransform with
member _.targetType() = typeof<Category>
member _.fromTargetType (value: obj) = box<Category> (value :?> Category)
member _.toTargetType (value: obj) = NotImplementedException()
type SubcategoryConverter() =
interface ITypeTransform with
member _.targetType() = typeof<Subcategory>
member _.fromTargetType (value: obj) = box<Subcategory> (value :?> Subcategory)
member _.toTargetType (value: obj) = NotImplementedException()
type AlternateSubcategoryConverter() =
interface ITypeTransform with
member _.targetType() = typeof<AlternateSubcategory>
member _.fromTargetType (value: obj) = box<AlternateSubcategory> (value :?> AlternateSubcategory)
member _.toTargetType (value: obj) = NotImplementedException()