/// <summary> /// 获取指定类型的对象序列化器 /// </summary> /// <param name="type"></param> /// <returns></returns> public static ITypeSerializer GetTypeSerializer(Type type) { try { var serialize = TypeSerializationHelper.GetTypeSerializer(type); return(serialize); } catch { throw; } }
/// <summary> /// 获取对象序列化器 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static ITypeSerializer GetTypeSerializer(object obj) { try { var serialize = TypeSerializationHelper.GetTypeSerializer(obj.GetType()); return(serialize); } catch { throw; } }
/// <summary> /// 序列化对象 /// </summary> /// <param name="message"></param> /// <returns></returns> public static byte[] Serialize(object message) { // 对象运行时类型 var type = message.GetType(); //获取对象序列化器 var serialize = TypeSerializationHelper.GetTypeSerializer(type); System.IO.MemoryStream ms = new System.IO.MemoryStream(); serialize.Serialize(message, ms); //返回序列化的字节数组 return(ms.ToArray()); }
/// <summary> /// /// </summary> /// <param name="typeCode"></param> /// <returns></returns> public static Type GetSerializerType(int typeCode) { var serialize = TypeSerializationHelper.GetTypeSerializer(typeCode.ToString()); return(serialize?.SerializerType); }