Commit 8f108e21 authored by Savorboard's avatar Savorboard

fixed json JObject bug

parent 0c831314
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Reflection; using System.Reflection;
using Newtonsoft.Json; using Newtonsoft.Json;
...@@ -43,13 +42,12 @@ namespace DotNetCore.CAP.Infrastructure ...@@ -43,13 +42,12 @@ namespace DotNetCore.CAP.Infrastructure
public static long ToTimestamp(DateTime value) public static long ToTimestamp(DateTime value)
{ {
var elapsedTime = value - Epoch; var elapsedTime = value - Epoch;
return (long)elapsedTime.TotalSeconds; return (long) elapsedTime.TotalSeconds;
} }
public static DateTime FromTimestamp(long value) public static DateTime FromTimestamp(long value)
{ {
// ReSharper disable once ImpureMethodCallOnReadonlyValueField
return Epoch.AddSeconds(value); return Epoch.AddSeconds(value);
} }
...@@ -73,31 +71,6 @@ namespace DotNetCore.CAP.Infrastructure ...@@ -73,31 +71,6 @@ namespace DotNetCore.CAP.Infrastructure
return !CanConvertFromString(type); return !CanConvertFromString(type);
} }
public static JObject ToJObject(Exception exception)
{
return new JObject(new
{
Source = exception.Source,
Message = exception.Message,
InnerMessage = exception.InnerException?.Message
});
}
public static string AddJsonProperty(string json, string propertyName, JObject propertyValue)
{
var jObj = JObject.Parse(json);
if (jObj.TryGetValue(propertyName, out var _))
{
jObj[propertyName] = propertyValue;
}
else
{
jObj.Add(new JProperty(propertyName, propertyValue));
}
return jObj.ToString();
}
public static string AddExceptionProperty(string json, Exception exception) public static string AddExceptionProperty(string json, Exception exception)
{ {
...@@ -160,5 +133,27 @@ namespace DotNetCore.CAP.Infrastructure ...@@ -160,5 +133,27 @@ namespace DotNetCore.CAP.Infrastructure
type == typeof(TimeSpan) || type == typeof(TimeSpan) ||
type == typeof(Uri); type == typeof(Uri);
} }
private static JObject ToJObject(Exception exception)
{
return JObject.FromObject(new
{
exception.Source,
exception.Message,
InnerMessage = exception.InnerException?.Message
});
}
private static string AddJsonProperty(string json, string propertyName, JObject propertyValue)
{
var jObj = JObject.Parse(json);
if (jObj.TryGetValue(propertyName, out var _))
jObj[propertyName] = propertyValue;
else
jObj.Add(new JProperty(propertyName, propertyValue));
return jObj.ToString(Formatting.None);
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment