TryConvertObjectToString method

bool TryConvertObjectToString(
  1. Object? value,
  2. OutParam<String> strValueOut
)
Try to convert object to a string. The value. The String representation of value.

Implementation

bool TryConvertObjectToString(Object? value, OutParam<String> strValueOut) {
//          print("TryConvertObjectToString(${value.runtimeType} $value)");
  bool converted = true;
  strValueOut.param = null;
  if (value != null) {
    if (EwsUtilities.TrySerializeEnum(value, strValueOut)) {
    }
//            if (value.getClass().isEnum()) {
//              str.setParam(EwsUtilities.serializeEnum(value));
//            } else if (value.getClass().equals(Boolean.class)) {
//              str.setParam(EwsUtilities.boolToXSBool((Boolean) value));
//            } else if (value instanceof Date) {
//              str
//                  .setParam(this.service
//                  .convertDateTimeToUniversalDateTimeString(
//                  (Date) value));
//            } else if (value.getClass().isPrimitive()) {
//              str.setParam(value.toString());
//            } else if (value instanceof String) {
//              str.setParam(value.toString());
//            } else if (value instanceof ISearchStringProvider) {
//              ISearchStringProvider searchStringProvider =
//              (ISearchStringProvider) value;
//              str.setParam(searchStringProvider.getSearchString());
//            } else if (value instanceof Number) {
//              str.setParam(value.toString());
    else if (value is DateTime) {
      strValueOut.param =
          this.Service.ConvertDateTimeToUniversalDateTimeString(value);
    } else if (value is int) {
      strValueOut.param = value.toString();
    } else if (value is bool) {
      strValueOut.param = value.toString();
    } else if (value is String) {
      strValueOut.param = value.toString();
    } else {
      converted = false;
      throw new NotImplementedException(
          "!!! TryConvertObjectToString ${value} of type ${value.runtimeType}");
    }
  }
  return converted;

//            strValueOut.param = null;
//            bool converted = true;
//
//            if (value != null)
//            {
//                // All value types should implement IConvertible. There are a couple of special cases
//                // that need to be handled directly. Otherwise use IConvertible.ToString()

//                IConvertible convertible = value as IConvertible;
//                if (value.GetType().IsEnum)
//                {
//                    strValue = EwsUtilities.SerializeEnum((Enum)value);
//                }
//                else if (convertible != null)
//                {
//                    switch (convertible.GetTypeCode())
//                    {
//                        case TypeCode.Boolean:
//                            strValue = EwsUtilities.BoolToXSBool((bool)value);
//                            break;
//
//                        case TypeCode.DateTime:
//                            strValue = this.Service.ConvertDateTimeToUniversalDateTimeString((DateTime)value);
//                            break;
//
//                        default:
//                            strValue = convertible.ToString(CultureInfo.InvariantCulture);
//                            break;
//                    }
//                }
//                else
//                {
//                    // If the value type doesn't implement IConvertible but implements IFormattable, use its
//                    // toString()(format,formatProvider) method to convert to a string.
//                    IFormattable formattable = value as IFormattable;
//                    if (formattable != null)
//                    {
//                        // Null arguments mean that we use default format and default locale.
//                        strValue = formattable.ToString(null, null);
//                    }
//                    else if (value is ISearchStringProvider)
//                    {
//                        // If the value type doesn't implement IConvertible or IFormattable but implements
//                        // ISearchStringProvider convert to a string.
//                        // Note: if a value type implements IConvertible or IFormattable we will *not* check
//                        // to see if it also implements ISearchStringProvider. We'll always use its IConvertible.ToString
//                        // or IFormattable.ToString method.
//                        ISearchStringProvider searchStringProvider = value as ISearchStringProvider;
//                        strValue = searchStringProvider.GetSearchString();
//                    }
//                    else if (value is Uint8List)
//                    {
//                        // Special case for byte arrays. Convert to Base64-encoded string.
//                        strValue = Convert.ToBase64String((Uint8List)value);
//                    }
//                    else
//                    {
//                        converted = false;
//                    }
//                }
//            }
//
//            return converted;
}