mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-11-08 18:34:44 +08:00
采用全新的数据库架构
This commit is contained in:
61
Infrastructure/JsonConverter.cs
Normal file
61
Infrastructure/JsonConverter.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : Infrastructure
|
||||
// Author : Yubao Li
|
||||
// Created : 09-07-2015
|
||||
//
|
||||
// Last Modified By : Yubao Li
|
||||
// Last Modified On : 09-07-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="GuidConverter.cs" company="">
|
||||
// Copyright (c) . All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>解决JSON转换空GUID问题</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Infrastructure
|
||||
{
|
||||
public class GuidConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType.IsAssignableFrom(typeof(Guid));
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
Guid result = Guid.Empty;
|
||||
if (reader.Value == null) return result;
|
||||
Guid.TryParse(reader.Value.ToString(), out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
serializer.Serialize(writer, value);
|
||||
}
|
||||
}
|
||||
|
||||
public class DecimalConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType.IsAssignableFrom(typeof(decimal));
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
decimal result = 0;
|
||||
if (reader.Value == null) return result;
|
||||
decimal.TryParse(reader.Value.ToString(), out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
serializer.Serialize(writer, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user