-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from itsharppro/dev
(#115) udpate webApi read query
- Loading branch information
Showing
4 changed files
with
65 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
43 changes: 43 additions & 0 deletions
43
src/Paralax.HTTP/src/Paralax.HTTP/NetJsonHttpClientSerializer.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using NetJSON; | ||
|
||
namespace Paralax.HTTP | ||
{ | ||
public class NetJsonHttpClientSerializer : IHttpClientSerializer | ||
{ | ||
private readonly NetJSONSettings _settings; | ||
|
||
public NetJsonHttpClientSerializer(NetJSONSettings settings = null) | ||
{ | ||
_settings = settings ?? new NetJSONSettings | ||
{ | ||
UseEnumString = true, | ||
CaseSensitive = false, | ||
SkipDefaultValue = true | ||
}; | ||
} | ||
|
||
public string Serialize<T>(T value) => NetJSON.NetJSON.Serialize(value, _settings); | ||
|
||
public async Task SerializeAsync<T>(Stream stream, T value) | ||
{ | ||
using (var writer = new StreamWriter(stream)) | ||
{ | ||
await writer.WriteAsync(NetJSON.NetJSON.Serialize(value, _settings)); | ||
await writer.FlushAsync(); | ||
} | ||
} | ||
|
||
public async ValueTask<T> DeserializeAsync<T>(Stream stream) | ||
{ | ||
using (var reader = new StreamReader(stream)) | ||
{ | ||
var content = await reader.ReadToEndAsync(); | ||
return NetJSON.NetJSON.Deserialize<T>(content, _settings); | ||
} | ||
} | ||
|
||
public T Deserialize<T>(string json) => NetJSON.NetJSON.Deserialize<T>(json, _settings); | ||
} | ||
} |
This file contains 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
This file contains 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