Imports System.IO
Imports Newtonsoft.Json
Friend Module ConfigurationSerializer
'''
''' Writes the given instance to a string and return it.
'''
'''
'''
Public Function WriteToString(instance As SimpleConfiguration) As String
Return JsonConvert.SerializeObject(instance)
End Function
'''
''' Write the given instance to a given stream.
'''
'''
'''
Public Sub WriteToStream(instance As SimpleConfiguration, stream As Stream)
Dim sr As New StreamWriter(stream)
sr.Write(WriteToString(instance))
End Sub
'''
''' Writes the given instance to the given filePath as text file.
'''
'''
'''
Public Sub WriteToFile(instance As SimpleConfiguration, filePath As String)
Dim fs As New FileStream(filePath, FileMode.Create)
WriteToStream(instance, fs)
fs.Close()
End Sub
'''
''' Reads a configuratin from the given string and returns an instance of it.
'''
'''
'''
'''
Public Function ReadFromString(Of T As SimpleConfiguration)(content As String) As T
Return JsonConvert.DeserializeObject(Of T)(content)
End Function
'''
''' Read a configuration from the given string and put them to the given instance.
'''
'''
'''
Public Sub ReadFromString(instance As SimpleConfiguration, content As String)
JsonConvert.PopulateObject(content, instance)
End Sub
End Module