Created
June 11, 2015 16:12
-
-
Save atifaziz/21b00c26ba6851ff6c69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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