当前位置: 首页 > news >正文

网站icon图标怎么设置休闲食品网站建设策划书

网站icon图标怎么设置,休闲食品网站建设策划书,引用评论框代码wordpress6,大二网页设计作业所谓的序列化就是是将对象转换为容易传输的格式的过程#xff0c;一般情况下转化打流文件#xff0c;放入内存或者IO文件中。例如#xff0c;可以序列化一个对象#xff0c;然后使用 HTTP 通过 Internet 在客户端和服务器之间传输该对象#xff0c;或者和其它应用程序共享…所谓的序列化就是是将对象转换为容易传输的格式的过程一般情况下转化打流文件放入内存或者IO文件中。例如可以序列化一个对象然后使用 HTTP 通过 Internet 在客户端和服务器之间传输该对象或者和其它应用程序共享使用。反之反序列化根据流重新构造对象。      .NET自带的有两种序列化对象的方式Xml和binary的XML 序列化不转换方法、索引器、私有字段或只读属性只读集合除外。要序列化对象的所有字段和属性公共的和私有的请使用 BinaryFormatter而不要使用 XML 序列化参见ms-help://MS.NETFramework.v20.chs/dv_fxserialization/html/8c63200d-db63-4a03-a93d-21641623df62.htmXML 和 SOAP 序列化。    两者的程序处理方式基本一致都是基于工厂模式的下面我就只说二进制的序列化的方式    例如我们有个对象 [Serializable]public class ClassToSerialize{     public int id100;     public string nameName; }    需要序列化该对象必须在给该类加上Serializable的属性然后创建一个序列化写入的流FileStream fileStream new FileStream(temp.dat, FileMode.Create);然后创建二进制格式器BinaryFormatter bnew BinaryFormatter();然后是序列化b.Serialize(fileStream,c);然后关闭保存流。可以见下面的例子      读取一个已经被序列化的对象的时候操作方式一样只是FileStream fileStream new FileStream(temp.dat, FileMode.Open, FileAccess.Read, FileShare.Read); ClassToSerialize c (ClassToSerialize)b.Deserialize(fileStream); 然后就可以读取了完整的例子是using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; public class SerialTest{     public void SerializeNow(){         ClassToSerialize cnew ClassToSerialize();         FileStream fileStream new FileStream(temp.dat, FileMode.Create);         BinaryFormatter bnew BinaryFormatter();         b.Serialize(fileStream,c);         fileStream.Close();     }     public void DeSerializeNow(){         ClassToSerialize cnew ClassToSerialize();         FileStream fileStream new FileStream(temp.dat, FileMode.Open, FileAccess.Read, FileShare.Read);         BinaryFormatter bnew BinaryFormatter();//SoapFormatter         c(ClassToSerialize)b.Deserialize(fileStream);         Console.WriteLine(c.name);         fileStream.Close();     }     public static void Main(string[] s){         SerialTest stnew SerialTest();         st.SerializeNow();         st.DeSerializeNow();     } } [Serializable] public class ClassToSerialize{     public int id100;     public string nameName; } 这就是自带的序列化和反序列的操作但是很多情况下一个对象比较大而且很多私有的属性和方法我们不需要例如在原型模式里面序列化的话只需要序列Clone方法和一些属性私有的方法无需要还例如在读取大规模的IO的时候读取操作完全不需要... 这时候就需要自己集成重写序列的ISerializable接口  实现该接口需要两个注意的一个就是构造函数主要是为了反序列另一个就是GetObjectData主要是执行序列化例如我们现在有一个Employee类需要序列化    [Serializable()]    //Set this attribute to all the classes that want to serialize     public class Employee : ISerializable //derive your class from ISerializable {         public int EmpId;         public string EmpName;         [NonSerialized()]     public string NoSerialStringNoSerialString-Test; } ,需要注意的是我这里的NoSerialString属性前面有[NonSerialized()]就是说默认并不序列化这个属性而是使用默认值 。  首先是构造函数        public Employee(SerializationInfo info, StreamingContext ctxt)         {             EmpId (int)info.GetValue(EmployeeId, typeof(int));             EmpName (String)info.GetValue(EmployeeName, typeof(string));             //NoSerialString (String)info.GetValue(NoSerialString, typeof(string));         } 然后是序列化方法就是当写入流的时候怎么保存的         public void GetObjectData(SerializationInfo info, StreamingContext ctxt)         {             //You can use any custom name for your name-value pair. But make sure you             // read the values with the same name. For ex:- If you write EmpId as EmployeeId             // then you should read the same with EmployeeId             info.AddValue(EmployeeId, EmpId);             info.AddValue(EmployeeName, EmpName);         } 把上面两个方法写入到Employee类然后写个测试的程序 public class ObjSerial{     public static void Main(String[] args){         Employee mp new Employee();         mp.EmpId 10;         mp.EmpName Omkumar;         mp.NoSerialString 你好啊;                        //序列化         Stream stream File.Open(EmployeeInfo.osl, FileMode.Create);         BinaryFormatter bformatter new BinaryFormatter();                         Console.WriteLine(Writing Employee Information);         bformatter.Serialize(stream, mp);         stream.Close();           mp null;        //反序列         stream File.Open(EmployeeInfo.osl, FileMode.Open);         bformatter new BinaryFormatter();                     Console.WriteLine(Reading Employee Information);         mp (Employee)bformatter.Deserialize(stream);         stream.Close();                         Console.WriteLine(Employee Id: {0},mp.EmpId.ToString());         Console.WriteLine(Employee Name: {0},mp.EmpName);         Console.WriteLine(Employee NoSerialString: {0},mp.NoSerialString);     } } 执行的结果是Writing Employee Information Reading Employee Information Employee Id: 10 Employee Name: Omkumar Employee NoSerialString: NoSerialString-Test    看到Employee NoSerialString:属性的值没有它保持默认值没有序列化。 转载于:https://www.cnblogs.com/MaxWoods/archive/2008/03/15/1107873.html
http://www.pierceye.com/news/431947/

相关文章:

  • 百度云建站WordPress开发新客户的十大渠道
  • 南宁比优建站视屏网站的审核是怎么做的
  • 怎样建设尧都水果网站免费手机网站建站系统
  • 全网营销提供seo服务
  • 吕梁网站设计服务器网站建设维护合同
  • 网站轮播图片怎么做高校网站建设模板
  • 易语言做返利网站企业培训考试平台官网
  • 天津做不锈钢的网站做网站要几个部门组成
  • 宿迁集团网站建设用dw制作一个网站
  • 网站创建二级域名网络营销到底是个啥
  • 银州手机网站建设做网站前台模型要做什么呢
  • 做彩票网站推广网站建设培训方案
  • o2o网站建设多少钱昆山专业网站建设
  • c语言自学免费网站网站制作职业
  • 免费刷赞网站推广qq免费有哪些网页设计软件
  • 如何设计网站的首页做海鲜代理在什么网站
  • 网站分析的优劣势苏州网络推广企业
  • 威海网站建设公司施工企业成本核算方法
  • 网站群集约化建设cc域名做门户网站
  • 怎么看一个网站做的好不好北京企业网站推广
  • 网站后台访问权限设置静宁网站建设
  • 网站是什么时候开始的怎样做知道网站
  • 安丘做网站的有那个网站
  • 网站建设佰首选金手指六门户网站 解决方案
  • 怎么可以创建网站十大管理培训课程
  • 网络安全管理系统佛山厂家推广优化
  • 网站建设 外包是什么意思微信小程序低代码开发
  • 网站底部信息用js写法莱芜雪野湖有什么好玩的
  • 青岛高品质网站制作优化快速排名教程
  • 地产项目网站长沙建个网站一般需要多少钱