/// <summary> /// 同时设置哈希表 <paramref name="key"/> 中一个或多个域值。 /// </summary> /// <param name="client">Redis 客户端。</param> /// <param name="key">键名</param> /// <param name="fieldValues">域值的匿名对象。</param> /// <returns>结果。</returns> public static Result HMSet(this IRedisClient client, string key, object fieldValues) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (fieldValues == null) { throw new ArgumentNullException(nameof(fieldValues)); } RedisDictionary redisDict; if (fieldValues is System.Collections.IDictionary) { redisDict = new RedisDictionary(fieldValues as System.Collections.IDictionary); } else { var typeMapper = TypeMapper.Create(fieldValues.GetType()); redisDict = new RedisDictionary(typeMapper.Count); foreach (var propertyMapper in typeMapper.Properties) { redisDict.Add(propertyMapper.Name, BinaryValue.Create(propertyMapper.GetValue(fieldValues, false), propertyMapper.Property)); } } return(HMSet(client, key, redisDict)); }
public void EnumTest() { TypeCode code = TypeCode.Int32; var value = BinaryValue.Create(code); Assert.Equal(code, (TypeCode)value.Parse(typeof(TypeCode))); }