1
я вставил свое классовое значение в Redis с помощью следующих методаRedis Get HashSet в нужный типа не работает с обнуляемым типом
public static bool InsertHashItem(string key, object obj)
{
bool result = false;
try
{
if (Muxer != null && Muxer.IsConnected && Muxer.GetDatabase() != null)
{
IDatabase getDatabase = Muxer.GetDatabase();
getDatabase.HashSet(key, ToHashEntries(obj));
result = true;
}
}
catch (Exception ex)
{
Logger.Fatal(ex.Message, ex);
}
return result;
}
Моего класс выглядит
public class TestType
{
public int telcoid { get; set; }
public int parent_id { get; set; }
public string checksum { get; set; }
public string tag_registration_id { get; set; }
public string market_id { get; set; }
public double amount { get; set; }
public string utid { get; set; }
public int status { get; set; }
public DateTime? dt { get; set; }
}
Теперь, чтобы получить этот класс я быть_наст написано метод, который терпит неудачу по типам с нулевым значением
public static T GetHashItem<T>(string key) where T : new()
{
T obj = default(T);
try
{
if (Muxer != null && Muxer.IsConnected && Muxer.GetDatabase() != null)
{
IDatabase getDatabase = Muxer.GetDatabase();
var hashkey = getDatabase.HashKeys(key);
if (hashkey != null && hashkey.Count() > 0)
{
var dic = hashkey.ToDictionary(k => k, k => getDatabase.HashGet(key, k));
obj = new T();
foreach (var prop in typeof(T).GetProperties())
{
prop.SetValue(obj, Convert.ChangeType(dic[prop.Name], prop.PropertyType));
}
}
}
}
catch (Exception ex)
{
Logger.Fatal(ex.Message, ex);
}
return obj;
}
Просьба сообщить, какая коррекция в ПЕД в нем
Спасибо. Попробовали, но похожи один бит по-разному. Но теперь попробуем ваш рекомендуемый. –