Exemplo n.º 1
0
        /// <summary>
        /// 轉換Class到HashEntry
        /// </summary>
        /// <param name="obj">Object</param>
        /// <returns></returns>
        public IEnumerable <HashEntry> Serialize(object obj)
        {
            PropertyInfo[] properties = obj.GetType().GetProperties();
            foreach (var property in properties)
            {
                var objVal = property.GetValue(obj);
                if (objVal == null)
                {
                    continue;
                }

                string redisValue = string.Empty;
                if (CustomSerializeFunc.ContainsKey(property.PropertyType))
                {
                    redisValue = CustomSerializeFunc[property.PropertyType](objVal);
                }
                else
                {
                    redisValue = DefaultSerialize(objVal);
                }

                string name = GetPropertyNameFunc(property);
                yield return(new HashEntry(name, redisValue));
            }
        }
Exemplo n.º 2
0
 public void RegisterCustomSerializeFunc(Type type, CustomSerializeFunc serialize)
 {
     if (null != serialize && !serializeDic.ContainsKey(type))
     {
         serializeDic.Add(type, serialize);
     }
 }
Exemplo n.º 3
0
 public void RegisterCustomSerializeFunc(Type type, CustomSerializeFunc serialize = null, CustomDeserializeFunc deserialize = null)
 {
     if (null != serialize && !serializeDic.ContainsKey(type))
     {
         serializeDic.Add(type, serialize);
     }
     if (null != deserialize && !deserializeDic.ContainsKey(type))
     {
         deserializeDic.Add(type, deserialize);
     }
 }
Exemplo n.º 4
0
 public bool TryGetSerializaFunc(Type type, out CustomSerializeFunc serializeFunc)
 {
     return(serializeDic.TryGetValue(type, out serializeFunc));
 }