public void TryParse() { { RedisValue val = "1"; int i; Assert.IsTrue(val.TryParse(out i)); Assert.AreEqual(1, i); long l; Assert.IsTrue(val.TryParse(out l)); Assert.AreEqual(1L, l); double d; Assert.IsTrue(val.TryParse(out d)); Assert.AreEqual(1.0, l); } { RedisValue val = "8675309"; int i; Assert.IsTrue(val.TryParse(out i)); Assert.AreEqual(8675309, i); long l; Assert.IsTrue(val.TryParse(out l)); Assert.AreEqual(8675309L, l); double d; Assert.IsTrue(val.TryParse(out d)); Assert.AreEqual(8675309.0, l); } { RedisValue val = "3.14159"; double d; Assert.IsTrue(val.TryParse(out d)); Assert.AreEqual(3.14159, d); } { RedisValue val = "not a real number"; int i; Assert.IsFalse(val.TryParse(out i)); long l; Assert.IsFalse(val.TryParse(out l)); double d; Assert.IsFalse(val.TryParse(out d)); } }
private object ConvertToBasicTypeObject <T>(RedisValue data) { switch (Type.GetTypeCode(typeof(T))) { case TypeCode.Byte: case TypeCode.SByte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: int temp1; if (data.TryParse(out temp1)) { return(temp1); } break; case TypeCode.Int64: case TypeCode.UInt64: int temp2; if (data.TryParse(out temp2)) { return(temp2); } break; case TypeCode.Double: case TypeCode.Decimal: case TypeCode.Single: double temp3; if (data.TryParse(out temp3)) { return(temp3); } break; case TypeCode.String: return(data.ToString()); } return(default(T)); }
internal static bool ToInt(this RedisValue redisValue, out int value) { value = default(int); if (!redisValue.HasValue) { return(false); } if (redisValue.IsNull) { return(true); } return(redisValue.TryParse(out value)); }
internal static bool ToDouble(this RedisValue redisValue, out double value) { value = default(double); if (!redisValue.HasValue) { return(false); } if (redisValue.IsNull) { return(true); } return(redisValue.TryParse(out value)); }
protected async void alarmTriggerReceived(RedisChannel channel, RedisValue message) { int alarm_channel; string zone_description = "Unknown"; if (message.TryParse(out alarm_channel)) { zone_description = zone_descriptions[alarm_channel]; } if (_chat_Id.HasValue) { await _botClient.SendTextMessageAsync( chatId : _chat_Id.Value, text : String.Format("Alarm triggered at {0}", zone_description)); } }
internal static bool ToNullableDouble(this RedisValue redisValue, out double?value) { value = null; if (!redisValue.HasValue) { return(false); } if (redisValue.IsNull) { return(true); } double result; if (redisValue.TryParse(out result)) { value = result; return(true); } return(false); }