public static Dictionary <string, string> ToHash(object instance, string keyPrefix = "") { if (instance == null) { throw new ArgumentNullException("entity"); } Dictionary <string, string> dic = new Dictionary <string, string>(); TypeAccessor ta = TypeAccessor.GetAccessor(instance.GetType()); if (ta.ReadWriteProperties.Count == 0) { throw new NotSupportedException(String.Format("对象 {0} 无任何的属性,无法使用 RedisHashCache 请使用 RedisCache.", instance.GetType().FullName)); } var values = ta.GetReadWritePropertyValues(instance); int index = 0; foreach (var property in ta.ReadWriteProperties) { dic.Add(keyPrefix + property.Name, ToString(values[index], property.PropertyType)); index++; } return(dic); }