protected string GetConfigStringValue(string key) { string value; value = _algorithm.GetParameter(key); if (value != null) { value = Config.GetValue <string>(key, value); } if (_enableParameterLog) { _algorithm.Log(string.Format("Parameter {0} set to {1}", key, value)); } if (value == null) { throw new ArgumentNullException(key, "The gene " + key + " is not present either as Config or as Parameter"); } return(value); }
protected override int GetConfigValue(string key) { int value; try { int.TryParse(_algorithm.GetParameter(key), out value); value = Config.GetInt(key, value); if (_enableParameterLog) { _algorithm.Log(string.Format("Parameter {0} set to {1}", key, value)); } } catch (ArgumentNullException e) { throw new ArgumentNullException(key, "The gene " + key + " is not present either as Config or as Parameter"); } return(value); }
/// <summary> /// Gets the gene int from key. /// </summary> /// <param name="key">The key.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">The gene " + key + " is not present either as Config or as Parameter</exception> /// <remarks> /// This method makes the algorithm working with the genes defined from the Config (as in the Lean Optimization) and /// from the Parameters (as the Lean Caller). /// </remarks> public static DateTime GetConfigDateTime(string key, DateTime def, QCAlgorithm algo) { // I'll keep this line as in the original code. //var gene = Config.GetValue<DateTime>(key, null); var gene = DateTime.MinValue; if (gene == DateTime.MinValue)//not found in config, then get from parameter { try { gene = DateTime.Parse(algo.GetParameter(key)); } #pragma warning disable CS0168 // Variable is declared but never used catch (ArgumentNullException e) #pragma warning restore CS0168 // Variable is declared but never used { return(def); } } return(gene); }
/// <summary> /// Gets the parameter with the specified name. If a parameter /// with the specified name does not exist, null is returned /// </summary> /// <param name="name">The name of the parameter to get</param> /// <returns>The value of the specified parameter, or null if not found</returns> public string GetParameter(string name) { return(_baseAlgorithm.GetParameter(name)); }