注塑空载具出库优化
This commit is contained in:
@@ -8,6 +8,7 @@ using JNPF;
|
||||
using JNPF.Common.Cache;
|
||||
using JNPF.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Tnb.Common.Redis
|
||||
{
|
||||
@@ -243,5 +244,25 @@ namespace Tnb.Common.Redis
|
||||
{
|
||||
return _instance.HSetAsync(key, field, value);
|
||||
}
|
||||
|
||||
public async Task<T> TryGetValueByKeyField<T>(string key, string field)
|
||||
{
|
||||
if (await _instance.HExistsAsync(key, field))
|
||||
{
|
||||
string data = await GetHash(key, field);
|
||||
Dictionary<String, String> json = JsonConvert.DeserializeObject<Dictionary<String, String>>(data);
|
||||
Type type = typeof(T);
|
||||
if (!type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)))
|
||||
{
|
||||
return (T)Convert.ChangeType(json["Value"],type.GetGenericArguments()[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (T)Convert.ChangeType(json["Value"],type);
|
||||
}
|
||||
// return ;
|
||||
}
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user