From b6b8d8177f6cf1e3ef1d5e387078a6908884f1c0 Mon Sep 17 00:00:00 2001 From: bosima Date: Tue, 10 Feb 2015 14:11:06 +0800 Subject: [PATCH] Update Types.cs Safety get an entry from the instance of the SerializationInfo. For s_down_time not exist. --- CSRedis/Types.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/CSRedis/Types.cs b/CSRedis/Types.cs index d423696..18b3f63 100644 --- a/CSRedis/Types.cs +++ b/CSRedis/Types.cs @@ -618,7 +618,10 @@ public class RedisSentinelInfo : RedisServerInfo public RedisSentinelInfo(SerializationInfo info, StreamingContext context) : base(info, context) { - SDownTime = info.GetInt64("s-down-time"); + // safety get from SerializationInfo + var s_down_time = GetSerializationItemValue(info, "s-down-time"); + + SDownTime = s_down_time == 0 ? -1 : s_down_time; LastHelloMessage = info.GetInt64("last-hello-message"); VotedLeader = info.GetString("voted-leader"); VotedLeaderEpoch = info.GetInt64("voted-leader-epoch"); @@ -642,6 +645,26 @@ public RedisSentinelInfo(SerializationInfo info, StreamingContext context) /// Get or set the voted-leader epoch /// public long VotedLeaderEpoch { get; set; } + + /// + /// Get a value from an instance of the SerializationInfo + /// + /// + /// + /// + /// + private T GetSerializationItemValue(SerializationInfo info, string key) + { + foreach (SerializationEntry entry in info) + { + if (entry.Name == key) + { + return (T)Convert.ChangeType(entry.Value, typeof(T), System.Globalization.CultureInfo.InvariantCulture); + } + } + + return default(T); + } } ///