Created
September 25, 2013 04:23
-
-
Save PaulGreenwell/6695143 to your computer and use it in GitHub Desktop.
VB.Net extension class that serialises and object to JSON
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
Imports System.IO | |
Imports Newtonsoft.Json | |
Imports Newtonsoft.Json.Converters | |
Imports System.Runtime.CompilerServices | |
Public Module JsonExtensions | |
<Extension()> | |
Public Function ToJson(ByVal entity As Object) As String | |
Dim serializer = New JsonSerializer() | |
serializer.Converters.Add(New StringEnumConverter()) | |
Using writer As New StringWriter() | |
serializer.Serialize(writer, entity) | |
Return writer.ToString() | |
End Using | |
End Function | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment