public void NumericUtility_TryParseDouble_1() { double value; Assert.IsTrue(NumericUtility.TryParseDouble("1.23", out value)); Assert.AreEqual(1.23, value); Assert.IsTrue(NumericUtility.TryParseDouble("1,23", out value)); Assert.AreEqual(1.23, value); Assert.IsFalse(NumericUtility.TryParseDouble("hello", out value)); Assert.IsFalse(NumericUtility.TryParseDouble(string.Empty, out value)); Assert.IsFalse(NumericUtility.TryParseDouble(null, out value)); }
/// <summary> /// Get double-precision float value from application configuration. /// </summary> public static double GetDouble ( [NotNull] string key, double defaultValue = 0.0 ) { string setting = CM.AppSettings[key]; if (!NumericUtility.TryParseDouble(setting, out double result)) { result = defaultValue; } return(result); }
/// <summary> /// Get double-precision float value from application configuration. /// </summary> public static double GetDouble ( [NotNull] string key, double defaultValue ) { #if DROID || ANDROID || UAP return(defaultValue); #else double result; string s = CM.AppSettings[key]; if (!NumericUtility.TryParseDouble(s, out result)) { result = defaultValue; } return(result); #endif }
/// <summary> /// Apply settings to the <see cref="IrbisConnection" />. /// </summary> public void ApplyToConnection ( [NotNull] IrbisConnection connection ) { Sure.NotNull(connection, nameof(connection)); connection.Host = _Select(Host, connection.Host); connection.Port = _Select(Port, connection.Port); connection.Username = _Select(Username, connection.Username); connection.Password = _Select(Password, connection.Password); connection.Database = _Select(Database, connection.Database); connection.Workstation = (IrbisWorkstation)_Select ( (int)Workstation, (int)connection.Workstation ); if (!string.IsNullOrEmpty(EngineTypeName)) { connection.SetEngine(EngineTypeName); } if (!string.IsNullOrEmpty(SocketTypeName)) { ClientSocketUtility.CreateSocket ( connection, SocketTypeName ); } if (!string.IsNullOrEmpty(NetworkLogging)) { connection.SetNetworkLogging(NetworkLogging); } if (!string.IsNullOrEmpty(FactoryTypeName)) { connection.SetCommandFactory(FactoryTypeName); } if (!string.IsNullOrEmpty(Smart)) { SmartClientSocket smartSocket = new SmartClientSocket(connection); connection.SetSocket(smartSocket); } if (!string.IsNullOrEmpty(Slow)) { SlowSocket slowSocket = new SlowSocket ( connection, connection.Socket ); int delay; if (NumericUtility.TryParseInt32(Slow, out delay) && delay > 0) { slowSocket.Delay = delay; } connection.SetSocket(slowSocket); } if (!string.IsNullOrEmpty(Broken)) { BrokenSocket brokenSocket = new BrokenSocket ( connection, connection.Socket ); double probability; if (NumericUtility.TryParseDouble(Broken, out probability) && probability > 0.0 && probability < 1.0) { brokenSocket.Probability = probability; } connection.SetSocket(brokenSocket); } if (RetryLimit != 0) { connection.SetRetry(RetryLimit, null); } if (!string.IsNullOrEmpty(UserData)) { connection.UserData = UserData; } connection._connected = Connected; }