- 3
- 0
- 约4.17千字
- 约 6页
- 2016-11-21 发布于重庆
- 举报
net下二进制序列化的格式分析
.net下二进制序列化的格式分析
相应c#下的序列化代码如下所示,程序把序列化后的数据存入了一个指定的文件file.bin里,分析这个文件数据主要为了能让非.Net下的应用程序读取序列化后数据,这有助于.net与其他语言平台的交互.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication2
{
[Serializable]
public class Object5
{
public int i1 = 0;
public int i2 = 0;
public float f3=0;
public string str;
}
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location = new System.Drawing.Point(72, 72);
this.button1.Name = button1;
this.button1.Size = new System.Drawing.Size(128, 32);
this.button1.TabIndex = 0;
this.button1.Text = button1;
this.button1.Click += new System.EventHandler(this.button1_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = Form1;
this.Text = Form1;
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
Object5 obj = new Object5();
obj.i1 = 128;
obj.i2 = 24;
obj.f3=1.3f;
obj.str = Some String;
double d1=1.3d;
float f1=1.3f;
int i1=1;
string s1=HelloWorld;
System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.Stream stream = new System.IO.File
原创力文档

文档评论(0)