Created
November 6, 2019 02:44
-
-
Save Olwiba/44a0f1fee3e367d4fa23c12eefb5039f to your computer and use it in GitHub Desktop.
RaygunSerializer c#
This file contains hidden or 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
using System; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Converters; | |
namespace YOUR.NAMESPACE | |
{ | |
internal static class RaygunSerializer | |
{ | |
private static readonly StringEnumConverter StringEnumConverter = new StringEnumConverter(); | |
private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings | |
{ | |
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor, | |
NullValueHandling = NullValueHandling.Ignore, | |
Formatting = Formatting.None, | |
Converters = new[] { StringEnumConverter } | |
}; | |
public static string Serialize<T>(T @object) | |
{ | |
return JsonConvert.SerializeObject(@object, Settings); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment