From 56b696bda4546f0fff72d913f68d6eebd5b9989c Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Wed, 16 Mar 2016 16:12:46 +0200 Subject: [PATCH] add support for char fields --- .../Picklers/PicklerResolver.fs | 1 + .../Picklers/PrimitivePicklers.fs | 16 ++++++++++++++ src/FSharp.AWS.DynamoDB/Utils/TypeShape.fs | 21 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/FSharp.AWS.DynamoDB/Picklers/PicklerResolver.fs b/src/FSharp.AWS.DynamoDB/Picklers/PicklerResolver.fs index 3b11285..e01d7a1 100644 --- a/src/FSharp.AWS.DynamoDB/Picklers/PicklerResolver.fs +++ b/src/FSharp.AWS.DynamoDB/Picklers/PicklerResolver.fs @@ -33,6 +33,7 @@ module private ResolverImpl = | :? ShapeSingle -> mkNumericalPickler () :> _ | :? ShapeDouble -> mkNumericalPickler () :> _ | :? ShapeDecimal -> mkNumericalPickler () :> _ + | :? ShapeChar -> new CharPickler() :> _ | :? ShapeString -> new StringPickler() :> _ | :? ShapeGuid -> new GuidPickler() :> _ | :? ShapeByteArray -> new ByteArrayPickler() :> _ diff --git a/src/FSharp.AWS.DynamoDB/Picklers/PrimitivePicklers.fs b/src/FSharp.AWS.DynamoDB/Picklers/PrimitivePicklers.fs index fa605bd..f6b1043 100644 --- a/src/FSharp.AWS.DynamoDB/Picklers/PrimitivePicklers.fs +++ b/src/FSharp.AWS.DynamoDB/Picklers/PrimitivePicklers.fs @@ -55,6 +55,22 @@ type StringPickler() = override __.Parse s = s override __.UnParse s = s +type CharPickler() = + inherit StringRepresentablePickler () + override __.PickleType = PickleType.String + override __.PicklerType = PicklerType.Value + override __.IsComparable = true + + override __.DefaultValue = char 0 + override __.Pickle c = AttributeValue(string c) |> Some + + override __.UnPickle a = + if not <| isNull a.S then System.Char.Parse(a.S) + else invalidCast a + + override __.Parse s = System.Char.Parse s + override __.UnParse c = string c + let inline mkNumericalPickler< ^N when ^N : (static member Parse : string * IFormatProvider -> ^N) and ^N : (member ToString : IFormatProvider -> string)> () = let inline parseNum s = diff --git a/src/FSharp.AWS.DynamoDB/Utils/TypeShape.fs b/src/FSharp.AWS.DynamoDB/Utils/TypeShape.fs index ee423bf..0254bb0 100644 --- a/src/FSharp.AWS.DynamoDB/Utils/TypeShape.fs +++ b/src/FSharp.AWS.DynamoDB/Utils/TypeShape.fs @@ -78,6 +78,10 @@ and ShapeDouble() = inherit TypeShape () override __.Accept (v : ITypeShapeVisitor<'R>) = v.VisitDouble() +and ShapeChar() = + inherit TypeShape () + override __.Accept (v : ITypeShapeVisitor<'R>) = v.VisitChar() + and ShapeString() = inherit TypeShape () override __.Accept (v : ITypeShapeVisitor<'R>) = v.VisitString() @@ -102,6 +106,14 @@ and ShapeDateTimeOffset() = inherit TypeShape () override __.Accept (v : ITypeShapeVisitor<'R>) = v.VisitDateTimeOffset() +and ShapeFSharpUnit() = + inherit TypeShape () + override __.Accept (v : ITypeShapeVisitor<'R>) = v.VisitFSharpUnit() + +and ShapeDBNull() = + inherit TypeShape () + override __.Accept (v : ITypeShapeVisitor<'R>) = v.VisitDBNull() + /////////////// Enumerations and IEnumVisitor<'R> = @@ -592,12 +604,15 @@ and ITypeShapeVisitor<'R> = abstract VisitUNativeInt : unit -> 'R abstract VisitSingle : unit -> 'R abstract VisitDouble : unit -> 'R + abstract VisitChar : unit -> 'R abstract VisitString : unit -> 'R abstract VisitGuid : unit -> 'R abstract VisitTimeSpan : unit -> 'R abstract VisitDateTime : unit -> 'R abstract VisitDateTimeOffset : unit -> 'R abstract VisitDecimal : unit -> 'R + abstract VisitFSharpUnit : unit -> 'R + abstract VisitDBNull : unit -> 'R abstract VisitUnknown<'T> : unit -> 'R @@ -700,6 +715,7 @@ module private TypeShapeImpl = elif t = typeof then ShapeDouble() :> _ elif t = typeof then ShapeNativeInt() :> _ elif t = typeof then ShapeUNativeInt() :> _ + elif t = typeof then ShapeChar() :> _ else activate1 typedefof> t elif t = typeof then ShapeDecimal() :> _ @@ -708,6 +724,8 @@ module private TypeShapeImpl = elif t = typeof then ShapeTimeSpan() :> _ elif t = typeof then ShapeDateTime() :> _ elif t = typeof then ShapeDateTimeOffset() :> _ + elif t = typeof then ShapeFSharpUnit() :> _ + elif t = typeof then ShapeDBNull() :> _ elif t.IsEnum then activate2 (getGenericEnumType()) t <| Enum.GetUnderlyingType t @@ -819,6 +837,7 @@ module TypeShapeModule = let (|ShapeUInt64|_|) t = test t let (|ShapeSingle|_|) t = test t let (|ShapeDouble|_|) t = test t + let (|ShapeChar|_|) t = test t let (|ShapeString|_|) t = test t let (|ShapeGuid|_|) t = test t @@ -826,6 +845,8 @@ module TypeShapeModule = let (|ShapeTimeSpan|_|) t = test t let (|ShapeDateTime|_|) t = test t let (|ShapeDateTimeOffset|_|) t = test t + let (|ShapeDBNull|_|) t = test t + let (|ShapeFSharpUnit|_|) t = test t let (|ShapeNullable|_|) t = test t let (|ShapeEnum|_|) t = test t