Skip to content

Commit

Permalink
add support for char fields
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriktsarpalis committed Mar 16, 2016
1 parent c959644 commit 56b696b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/FSharp.AWS.DynamoDB/Picklers/PicklerResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module private ResolverImpl =
| :? ShapeSingle -> mkNumericalPickler<single> () :> _
| :? ShapeDouble -> mkNumericalPickler<double> () :> _
| :? ShapeDecimal -> mkNumericalPickler<decimal> () :> _
| :? ShapeChar -> new CharPickler() :> _
| :? ShapeString -> new StringPickler() :> _
| :? ShapeGuid -> new GuidPickler() :> _
| :? ShapeByteArray -> new ByteArrayPickler() :> _
Expand Down
16 changes: 16 additions & 0 deletions src/FSharp.AWS.DynamoDB/Picklers/PrimitivePicklers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ type StringPickler() =
override __.Parse s = s
override __.UnParse s = s

type CharPickler() =
inherit StringRepresentablePickler<char> ()
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 =
Expand Down
21 changes: 21 additions & 0 deletions src/FSharp.AWS.DynamoDB/Utils/TypeShape.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ and ShapeDouble() =
inherit TypeShape<double> ()
override __.Accept (v : ITypeShapeVisitor<'R>) = v.VisitDouble()

and ShapeChar() =
inherit TypeShape<char> ()
override __.Accept (v : ITypeShapeVisitor<'R>) = v.VisitChar()

and ShapeString() =
inherit TypeShape<string> ()
override __.Accept (v : ITypeShapeVisitor<'R>) = v.VisitString()
Expand All @@ -102,6 +106,14 @@ and ShapeDateTimeOffset() =
inherit TypeShape<DateTimeOffset> ()
override __.Accept (v : ITypeShapeVisitor<'R>) = v.VisitDateTimeOffset()

and ShapeFSharpUnit() =
inherit TypeShape<unit> ()
override __.Accept (v : ITypeShapeVisitor<'R>) = v.VisitFSharpUnit()

and ShapeDBNull() =
inherit TypeShape<DBNull> ()
override __.Accept (v : ITypeShapeVisitor<'R>) = v.VisitDBNull()

/////////////// Enumerations

and IEnumVisitor<'R> =
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -700,6 +715,7 @@ module private TypeShapeImpl =
elif t = typeof<double> then ShapeDouble() :> _
elif t = typeof<nativeint> then ShapeNativeInt() :> _
elif t = typeof<unativeint> then ShapeUNativeInt() :> _
elif t = typeof<char> then ShapeChar() :> _
else activate1 typedefof<ShapeUnknown<_>> t

elif t = typeof<decimal> then ShapeDecimal() :> _
Expand All @@ -708,6 +724,8 @@ module private TypeShapeImpl =
elif t = typeof<TimeSpan> then ShapeTimeSpan() :> _
elif t = typeof<DateTime> then ShapeDateTime() :> _
elif t = typeof<DateTimeOffset> then ShapeDateTimeOffset() :> _
elif t = typeof<unit> then ShapeFSharpUnit() :> _
elif t = typeof<DBNull> then ShapeDBNull() :> _

elif t.IsEnum then
activate2 (getGenericEnumType()) t <| Enum.GetUnderlyingType t
Expand Down Expand Up @@ -819,13 +837,16 @@ module TypeShapeModule =
let (|ShapeUInt64|_|) t = test<ShapeUInt64> t
let (|ShapeSingle|_|) t = test<ShapeSingle> t
let (|ShapeDouble|_|) t = test<ShapeDouble> t
let (|ShapeChar|_|) t = test<ShapeChar> t

let (|ShapeString|_|) t = test<ShapeString> t
let (|ShapeGuid|_|) t = test<ShapeGuid> t
let (|ShapeDecimal|_|) t = test<ShapeDecimal> t
let (|ShapeTimeSpan|_|) t = test<ShapeTimeSpan> t
let (|ShapeDateTime|_|) t = test<ShapeDateTime> t
let (|ShapeDateTimeOffset|_|) t = test<ShapeDateTimeOffset> t
let (|ShapeDBNull|_|) t = test<ShapeDBNull> t
let (|ShapeFSharpUnit|_|) t = test<ShapeFSharpUnit> t

let (|ShapeNullable|_|) t = test<IShapeNullable> t
let (|ShapeEnum|_|) t = test<IShapeEnum> t
Expand Down

0 comments on commit 56b696b

Please sign in to comment.