2using System.Xml.Serialization;
16[XmlType(TypeName =
"algorithmParameter")]
19 private string _name =
string.Empty;
20 private string _value =
string.Empty;
21 private string _dataType =
string.Empty;
22 private string _description =
string.Empty;
54 string description =
"")
65 [XmlAttribute(
"name")]
71 if (
string.IsNullOrWhiteSpace(value))
73 throw new ArgumentException(
74 "The parameter name cannot be empty.",
85 [XmlAttribute(
"value")]
89 set => _value = value ??
string.Empty;
99 [XmlAttribute(
"dataType")]
103 set => _dataType = value?.Trim() ??
string.Empty;
110 [XmlElement(
"description")]
114 set => _description = value ??
string.Empty;
135 string description =
"")
140 System.Globalization.CultureInfo.InvariantCulture),
163 string description =
"")
165 if (!
double.IsFinite(value))
167 throw new ArgumentOutOfRangeException(
170 "The parameter value must be finite.");
177 System.Globalization.CultureInfo.InvariantCulture),
200 string description =
"")
204 value ?
"true" :
"false",
227 string description =
"")
231 value ??
string.Empty,
249 System.Globalization.NumberStyles.Integer,
250 System.Globalization.CultureInfo.InvariantCulture,
267 bool parsed =
double.TryParse(
269 System.Globalization.NumberStyles.Float,
270 System.Globalization.CultureInfo.InvariantCulture,
274 double.IsFinite(value);
288 return bool.TryParse(
296 return string.IsNullOrWhiteSpace(
DataType)
297 ? $
"{Name} = {Value}"
298 : $
"{Name} = {Value} ({DataType})";
string Value
Gets or sets the serialized parameter value.
AlgorithmParameter(string name, string value, string dataType="", string description="")
Initializes a named algorithm parameter.
string Name
Gets or sets the parameter name.
string DataType
Gets or sets an optional description of the value type.
override string ToString()
bool TryGetInteger(out int value)
Attempts to read the parameter value as an integer.
AlgorithmParameter()
Initializes an empty algorithm parameter.
bool TryGetDouble(out double value)
Attempts to read the parameter value as a floating-point number.
static AlgorithmParameter FromDouble(string name, double value, string description="")
Creates a floating-point algorithm parameter.
static AlgorithmParameter FromBoolean(string name, bool value, string description="")
Creates a Boolean algorithm parameter.
bool TryGetBoolean(out bool value)
Attempts to read the parameter value as a Boolean.
static AlgorithmParameter FromInteger(string name, int value, string description="")
Creates an integer algorithm parameter.
string Description
Gets or sets an optional human-readable description of the parameter.
static AlgorithmParameter FromString(string name, string value, string description="")
Creates a string algorithm parameter.