首页 > 代码库 > BinaryFormaterSerializer类(NetworkComms 2.3.1源码了解和学习)
BinaryFormaterSerializer类(NetworkComms 2.3.1源码了解和学习)
networkComms.net2.3.1开源版本,基于gpl V3协议。因为不能公开3.x版本的源码,所以基于此版本进行学习。3.X版本进行了诸多改进和Bug修复,使用方法上两者相差不大。/*请注意使用以下代码,需遵循GplV3协议*/#if WINDOWS_PHONE#elseusing System;using System.Collections.Generic;using System.Text;using System.Runtime.Serialization.Formatters.Binary;using System.IO;#if ANDROIDusing PreserveAttribute = Android.Runtime.PreserveAttribute;#elif iOSusing PreserveAttribute = MonoTouch.Foundation.PreserveAttribute;#endifnamespace DPSBase{ /// .net自带的序列化器 /// </summary> [DataSerializerProcessor(2)] public class BinaryFormaterSerializer : DataSerializer { static DataSerializer instance; [Obsolete("Instance access via class obsolete, use DPSManager.GetSerializer<T>")] public static DataSerializer Instance { get { if (instance == null) instance = GetInstance<BinaryFormaterSerializer>(); return instance; } }#if ANDROID || iOS [Preserve]#endif private BinaryFormaterSerializer() { } #region ISerialize Members /// <inheritdoc /> /// 把对象序列化为二进制数据 protected override void SerialiseDataObjectInt(Stream ouputStream, object objectToSerialise, Dictionary<string, string> options) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(ouputStream, objectToSerialise); ouputStream.Seek(0, 0); } /// <inheritdoc /> /// 把二进制数据序列化为对象 protected override object DeserialiseDataObjectInt(Stream inputStream, Type resultType, Dictionary<string, string> options) { BinaryFormatter formatter = new BinaryFormatter(); return formatter.Deserialize(inputStream); } #endregion }}#endif http://www.cnblogs.com/networkcommshttp://www.networkcoms.cn 编辑
BinaryFormaterSerializer类(NetworkComms 2.3.1源码了解和学习)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。