packages feed

servant-csharp 0.0.3.0 → 0.0.4.0

raw patch · 3 files changed

+40/−1 lines, 3 files

Files

servant-csharp.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                servant-csharp-version:             0.0.3.0+version:             0.0.4.0 synopsis:            Generate servant client library for C# description:         Generate servant client library for C# homepage:            https://github.com/cutsea110/servant-csharp.git
src/CS.hs view
@@ -2,6 +2,8 @@           , apiCsForAPIWith           , enumCsForAPI           , enumCsForAPIWith+          , converterCsForAPI+          , converterCsForAPIWith            , GenerateCsConfig(..)           , def
src/CS/JsonDotNet.hs view
@@ -8,6 +8,8 @@                      , apiCsForAPIWith                      , enumCsForAPI                      , enumCsForAPIWith+                     , converterCsForAPI+                     , converterCsForAPIWith                       , GenerateCsConfig(..)                      , def@@ -39,6 +41,7 @@                                      -> Proxy api                                      -> IO String                        , enumtemplate :: GenerateCsConfig -> IO String+                       , convtemplate :: GenerateCsConfig -> IO String                        , sources :: [FilePath]                        } @@ -46,6 +49,7 @@ def = GenerateCsConfig { namespace = "ServantClientAPI"                        , apitemplate = defAPITemplate                        , enumtemplate = defEnumTemplate+                       , convtemplate = defConvTemplate                        , sources = []                        } @@ -197,6 +201,12 @@ enumCsForAPIWith :: GenerateCsConfig -> IO String enumCsForAPIWith conf = (enumtemplate conf) conf +converterCsForAPI :: IO String+converterCsForAPI = converterCsForAPIWith def++converterCsForAPIWith :: GenerateCsConfig -> IO String+converterCsForAPIWith conf = (convtemplate conf) conf+ defAPITemplate :: (HasForeign CSharp Text api,                 GenerateList Text (Foreign Text api)) =>                GenerateCsConfig -> Proxy api -> IO String@@ -309,3 +319,30 @@ } |] +defConvTemplate conf = do+  return [heredoc|+using Newtonsoft.Json;+using System;++namespace ${namespace conf}+{+    public class DayConverter : JsonConverter+    {+        public override bool CanConvert(Type objectType)+        {+            return objectType == typeof(DateTime);+        }++        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)+        {+            return DateTime.Parse((string)reader.Value);+        }++        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)+        {+            DateTime d = (DateTime)value;+            writer.WriteValue(d.ToString("yyyy-MM-dd"));+        }+    }+}+|]