This repository has been archived by the owner on Jan 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Sample JavaScriptConverter
Vince Lee edited this page Apr 5, 2016
·
2 revisions
using Nancy.Json;
public class DatePartsConverter : JavaScriptConverter
{
public override IEnumerable<Type> SupportedTypes
{
get { yield return typeof(DateTime); }
}
public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
{
if (obj is DateTime)
{
DateTime date = (DateTime)obj;
var json = new Dictionary<string, object>();
json["year"] = date.Year;
json["month"] = date.Month;
json["day"] = date.Day;
return json;
}
return null;
}
public override object Deserialize(IDictionary<string, object> json, Type type, JavaScriptSerializer serializer)
{
if (type == typeof(DateTime))
{
object year, month, day;
json.TryGetValue("year", out year);
json.TryGetValue("month", out month);
json.TryGetValue("day", out day);
if ((year is int)
&& (month is int)
&& (day is int))
return new DateTime((int)year, (int)month, (int)day);
}
return null;
}
}
- Introduction
- Exploring the Nancy module
- Routing
- Taking a look at the DynamicDictionary
- Async
- View Engines
- Using Models
- Managing static content
- Authentication
- Lifecycle of a Nancy Application
- Bootstrapper
- Adding a custom FavIcon
- Diagnostics
- Generating a custom error page
- Localization
- SSL Behind Proxy
- Testing your application
- The cryptography helpers
- Validation
- Hosting Nancy with ASP.NET
- Hosting Nancy with WCF
- Hosting Nancy with Azure
- Hosting Nancy with Suave.IO
- Hosting Nancy with OWIN
- Hosting Nancy with Umbraco
- Hosting Nancy with Nginx on Ubuntu
- Hosting Nancy with FastCgi
- Self Hosting Nancy
- Implementing a Host
- Accessing the client certificate when using SSL
- Running Nancy on your Raspberry Pi
- Running Nancy with ASP.NET Core 3.1