Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Created June 11, 2015 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atifaziz/21b00c26ba6851ff6c69 to your computer and use it in GitHub Desktop.
Save atifaziz/21b00c26ba6851ff6c69 to your computer and use it in GitHub Desktop.
// https://groups.google.com/d/msg/jayrock/t5GI2ta5Pow/p3_CtsWFiPIJ
using System;
using System.Globalization;
using Jayrock.Json;
using Jayrock.Json.Conversion;
using Jayrock.Json.Conversion.Converters;
sealed class TimeSpanImporter : ImporterBase
{
public TimeSpanImporter() : base(typeof(TimeSpan)) { }
protected override object ImportFromString(ImportContext context, JsonReader reader)
{
return TimeSpan.Parse(reader.ReadString(), CultureInfo.InvariantCulture);
}
}
public class ETest
{
public TimeSpan tm { get; set; }
}
static class Program
{
static void Main()
{
var context = JsonConvert.CreateImportContext();
context.Register(new TimeSpanImporter());
const string json = "{\"tm\":\"11:28:47\"}";
var eTest = context.Import<ETest>(JsonText.CreateReader(json));
Console.WriteLine(eTest.tm);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment