File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- using System . IO ;
2- using System . Runtime . Serialization . Formatters . Binary ;
1+ using System . Text . Json ;
32
43namespace SingleInstanceCore
54{
65 //For inline serializing and deserializing
76 internal static class SerializationExtensions
87 {
9- private static readonly BinaryFormatter Formatter = new BinaryFormatter ( ) ;
8+ private static readonly JsonSerializerOptions serializerOptions = new JsonSerializerOptions ( )
9+ {
10+ PropertyNamingPolicy = null ,
11+ AllowTrailingCommas = true
12+ } ;
1013
1114 internal static byte [ ] Serialize < T > ( this T obj )
1215 {
13- using var memoryStream = new MemoryStream ( ) ;
14- Formatter . Serialize ( memoryStream , obj ) ;
15- return memoryStream . ToArray ( ) ;
16+ return JsonSerializer . SerializeToUtf8Bytes ( obj , serializerOptions ) ;
1617 }
1718
1819 internal static T Deserialize < T > ( this byte [ ] data )
1920 {
20- using var memoryStream = new MemoryStream ( data ) ;
21- var obj = Formatter . Deserialize ( memoryStream ) ;
22- return ( T ) obj ;
21+ return JsonSerializer . Deserialize < T > ( data , serializerOptions ) ;
2322 }
2423 }
2524}
You can’t perform that action at this time.
0 commit comments