Ejemplo n.º 1
0
        /// <summary> 反序列化 | Deserialize(Parse bytes to object) </summary>
        /// <param name="typeName">自定义类型名称 | Custom type name</param>
        /// <param name="bytes">字节数组 | Byte array</param>
        public static T Deserialize <T>(string typeName, byte[] bytes) where T : new()
        {
            LBType customType;

            if (!LBConfig.TryGetCustomType(typeName, out customType))
            {
                throw new Exception("CustomType is null. Type name:" + typeName);
            }
            return(LBConverter.ToObject <T>(customType, bytes));
        }
Ejemplo n.º 2
0
        /// <summary> 序列化(对象转字节数组) | Serialize(Convert object to bytes) </summary>
        /// <param name="typeName">自定义类型名称 | Custom type name</param>
        /// <param name="obj">对象(类或结构) | object(class or struct)</param>
        public static byte[] Serialize(string typeName, object obj)
        {
            LBType customType;

            if (!LBConfig.TryGetCustomType(typeName, out customType))
            {
                throw new Exception("CustomType is null. Type name:" + typeName);
            }
            return(LBConverter.ToBytes(customType, obj));
        }