TryConvertObjectToString method
Try to convert object to a string.
The value.
The String representation of value.
Implementation
bool TryConvertObjectToString(Object? value, OutParam<String> strValueOut) {
strValueOut.param = null;
bool converted = true;
if (value != null) {
// Enums go through the EWS name maps first; other enums use their name,
// like C# EwsUtilities.SerializeEnum falls back to Enum.ToString().
if (EwsUtilities.TrySerializeEnum(value, strValueOut)) {
} else if (value is Enum) {
strValueOut.param = value.name;
} else if (value is bool) {
strValueOut.param = EwsUtilities.BoolToXSBool(value);
} else if (value is DateTime) {
strValueOut.param = Service.ConvertDateTimeToUniversalDateTimeString(
value,
);
} else if (value is String) {
strValueOut.param = value;
} else if (value is int || value is BigInt) {
strValueOut.param = value.toString();
} else if (value is double) {
// C# formats integral doubles without a fractional part ("1", not "1.0").
strValueOut.param = value.isFinite && value == value.truncateToDouble()
? value.toStringAsFixed(0)
: value.toString();
} else if (value is TimeSpan) {
// IFormattable in C#.
strValueOut.param = value.toString();
} else if (value is Uuid) {
// Guid is IFormattable in C#; its default format is the plain id.
strValueOut.param = value.value;
} else if (value is ISearchStringProvider) {
// If the value type doesn't implement IConvertible or IFormattable but implements
// ISearchStringProvider convert to a string.
strValueOut.param = value.GetSearchString();
} else if (value is List<int>) {
// Special case for byte arrays. Convert to Base64-encoded string.
strValueOut.param = base64.encode(value);
} else {
converted = false;
}
}
return converted;
}