1- using Elasticsearch . Net ;
2- using Newtonsoft . Json ;
3- using System ;
4- using System . IO ;
5- using System . Threading ;
6- using System . Threading . Tasks ;
7-
8- namespace Serilog . Ui . ElasticSearchProvider
9- {
10- internal class VanillaSerializer : IElasticsearchSerializer
11- {
12- public T Deserialize < T > ( Stream stream ) => ( T ) Deserialize ( typeof ( T ) , stream ) ;
13-
14- public object Deserialize ( Type type , Stream stream )
15- {
16- var reader = new StreamReader ( stream ) ;
17-
18- using ( var jsonTextReader = new JsonTextReader ( reader ) )
19- {
20- var serializer = new JsonSerializer ( ) ;
21- return serializer . Deserialize ( jsonTextReader , type ) ;
22- }
23- }
24-
25- public Task < T > DeserializeAsync < T > ( Stream stream , CancellationToken cancellationToken = default ) =>
26- Task . FromResult ( Deserialize < T > ( stream ) ) ;
27-
28- public Task < object > DeserializeAsync ( Type type , Stream stream , CancellationToken cancellationToken = default ) =>
29- Task . FromResult ( Deserialize ( type , stream ) ) ;
30-
31- public void Serialize < T > ( T data , Stream stream , SerializationFormatting formatting = SerializationFormatting . Indented )
32- {
33- var writer = new StreamWriter ( stream ) ;
34-
35- using ( var jWriter = new JsonTextWriter ( writer ) )
36- {
37- var serializer = new JsonSerializer
38- {
39- Formatting = formatting == SerializationFormatting . Indented ? Formatting . Indented : Formatting . None
40- } ;
41- serializer . Serialize ( jWriter , data ) ;
42- }
43- }
44-
45- public Task SerializeAsync < T > (
46- T data ,
47- Stream stream ,
48- SerializationFormatting formatting = SerializationFormatting . Indented ,
49- CancellationToken cancellationToken = default )
50- {
51- Serialize ( data , stream , formatting ) ;
52-
53- return Task . CompletedTask ;
54- }
55- }
1+ using Elasticsearch . Net ;
2+ using Newtonsoft . Json ;
3+ using System ;
4+ using System . IO ;
5+ using System . Threading ;
6+ using System . Threading . Tasks ;
7+
8+ namespace Serilog . Ui . ElasticSearchProvider
9+ {
10+ internal class VanillaSerializer : IElasticsearchSerializer
11+ {
12+ public T Deserialize < T > ( Stream stream ) => ( T ) Deserialize ( typeof ( T ) , stream ) ;
13+
14+ public object Deserialize ( Type type , Stream stream )
15+ {
16+ var reader = new StreamReader ( stream ) ;
17+
18+ using ( var jsonTextReader = new JsonTextReader ( reader ) )
19+ {
20+ var serializer = new JsonSerializer ( ) ;
21+ return serializer . Deserialize ( jsonTextReader , type ) ;
22+ }
23+ }
24+
25+ public Task < T > DeserializeAsync < T > ( Stream stream , CancellationToken cancellationToken = default ) =>
26+ Task . FromResult ( Deserialize < T > ( stream ) ) ;
27+
28+ public Task < object > DeserializeAsync ( Type type , Stream stream , CancellationToken cancellationToken = default ) =>
29+ Task . FromResult ( Deserialize ( type , stream ) ) ;
30+
31+ public void Serialize < T > ( T data , Stream stream , SerializationFormatting formatting = SerializationFormatting . None )
32+ {
33+ var writer = new StreamWriter ( stream ) ;
34+
35+ using ( var jWriter = new JsonTextWriter ( writer ) )
36+ {
37+ var serializer = new JsonSerializer
38+ {
39+ Formatting = formatting == SerializationFormatting . Indented ? Formatting . Indented : Formatting . None
40+ } ;
41+ serializer . Serialize ( jWriter , data ) ;
42+ }
43+ }
44+
45+ public Task SerializeAsync < T > (
46+ T data ,
47+ Stream stream ,
48+ SerializationFormatting formatting = SerializationFormatting . None ,
49+ CancellationToken cancellationToken = default )
50+ {
51+ Serialize ( data , stream , formatting ) ;
52+
53+ return Task . CompletedTask ;
54+ }
55+ }
5656}
0 commit comments