標籤:
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源碼瞭解和學習)