Biser
v1.9
.NET dotnet的跨平台二進制和JSON序列化器。
raft.net中使用的dbreeze數據庫的集成部分
致電下行以為序列化創建代碼:
var resbof = BiserObjectify . Generator . Run ( typeof ( TS6 ) , true ,
@"D:Temp1" , forBiserBinary : true , forBiserJson : true , null ) ;第一個參數是要序列化的根對象的類型(它可以包含其他也必須序列化的對象)。第二個參數意味著Biserobjectify必須為根對像中包含的所有對象準備序列化器。第三個參數指向將創建每個對象C c#文件的文件夾。第四和第五論點意味著我們要同時使用二進制和JSON序列化。第六個參數是標籤(或null),其屬性名稱不會序列化。
RESBOF變量將包含與生成文件一樣作為字典中的相同信息。
public partial class TS6
{
public string P1 { get ; set ; }
.. . TS6 t6 = new TS6 ( )
{
P1 = "dsfs" ,
P2 = 456 ,
P3 = DateTime . UtcNow ,
P4 = new List < Dictionary < DateTime , Tuple < int , string > >>
{
new Dictionary < DateTime , Tuple < int , string > > {
{ DateTime . UtcNow . AddMinutes ( - 1 ) , new Tuple < int , string > ( 12 , "testvar" ) } ,
{ DateTime . UtcNow . AddMinutes ( - 2 ) , new Tuple < int , string > ( 125 , "testvar123" ) }
} ,
new Dictionary < DateTime , Tuple < int , string > > {
{ DateTime . UtcNow . AddMinutes ( - 3 ) , new Tuple < int , string > ( 17 , "dsfsdtestvar" ) } ,
{ DateTime . UtcNow . AddMinutes ( - 4 ) , new Tuple < int , string > ( 15625 , "sdfsdtestvar" ) }
}
} ,
P5 = new Dictionary < int , Tuple < int , string > > {
{ 12 , new Tuple < int , string > ( 478 , "dsffdf" ) } ,
{ 178 , new Tuple < int , string > ( 5687 , "sdfsd" ) }
} ,
P6 = new Tuple < int , string , Tuple < List < string > , DateTime > > ( 445 , "dsfdfgfgfg" ,
new Tuple < List < string > , DateTime > ( new List < string > { "a1" , "a2" } , DateTime . Now . AddDays ( 58 ) ) ) ,
P7 = new List < string > { "fgdfgrdfg" , "dfgfdgdfg" } ,
P8 = new Dictionary < int , List < string > > {
{ 34 , new List < string > { "drtttz" , "ghhtht" } } ,
{ 4534 , new List < string > { "dfgfghfgz" , "6546ghhtht" } }
} ,
P25 = new Dictionary < int , List < string [ , ] [ ] [ , , ] > > [ , , , ] [ ] [ , , ]
.. .
} var serializedObjectAsByteArray = t6 . BiserEncoder ( ) . Encode ( ) ;
var retoredBinaryObject = TS6 . BiserDecode ( serializedObjectAsByteArray ) ; var jsonSettings = new Biser . JsonSettings { DateFormat = Biser . JsonSettings . DateTimeStyle . ISO } ;
string prettifiedJsonString = new Biser . JsonEncoder ( t6 , jsonSettings )
. GetJSON ( Biser . JsonSettings . JsonStringStyle . Prettify ) ;
var restoredJsonObject = TS6 . BiserJsonDecode ( prettifiedJsonString , settings : jsonSettings ) ; 為了深入了解:
文檔二進制雙頭
文檔JSON BISER
手動編碼器/解碼器的示例