/// <summary> /// Formats the field value in the appropriate line protocol format based on the type of the value object. /// The value type must be a string, boolean, or integral or floating-point type. /// </summary> /// <param name="value">The field value to format.</param> /// <returns>The field value formatted as a string used in the line protocol format.</returns> public static String FormatValue(Object value) { Type type = value?.GetType(); if (value == null) { throw new ArgumentNullException(nameof(value)); } if (!InfluxUtils.IsValidValueType(type)) { throw new ArgumentException(nameof(value), $"Value is not one of the supported types: {type} - Valid types: {String.Join(", ", InfluxUtils.ValidValueTypes.Select(t => t.Name))}"); } if (InfluxUtils.IsIntegralType(type)) { return(FormatValue(Convert.ToInt64(value))); } if (InfluxUtils.IsFloatingPointType(type)) { return(FormatValue(Convert.ToDouble(value))); } if (value is Boolean) { return(FormatValue((Boolean)value)); } if (value is String) { return(FormatValue((String)value)); } if (value is Char) { return(FormatValue(value.ToString())); } return(FormatValue(value.ToString())); }