Exemplo n.º 1
0
        public object Encode(object value)
        {
            switch (value)
            {
            case DateTime _:
                return(new Dictionary <string, object>
                {
                    ["iso"] = ((DateTime)value).ToString(ParseClient.DateFormatStrings.First(), CultureInfo.InvariantCulture),
                    ["__type"] = "Date"
                });

            case byte[] bytes:
                return(new Dictionary <string, object>
                {
                    ["__type"] = "Bytes",
                    ["base64"] = Convert.ToBase64String(bytes)
                });

            case ParseObject obj:
                return(EncodeParseObject(obj));

            case IJsonConvertible jsonConvertible:
                return(jsonConvertible.ToJSON());

            case object _ when ConversionHelpers.DowncastReference <IDictionary <string, object> >(value) is IDictionary <string, object> dict:
                Dictionary <string, object> json = new Dictionary <string, object>
                {
                };
                foreach (KeyValuePair <string, object> pair in dict)
                {
                    json[pair.Key] = Encode(pair.Value);
                }

                return(json);

            case object _ when ConversionHelpers.DowncastReference <IList <object> >(value) is IList <object> list:
                return(EncodeList(list));

            case IParseFieldOperation operation:
                // TODO: Convert IParseFieldOperation to IJsonConvertible.
                return(operation.Encode());

            default:
                return(value);
            }
        }
Exemplo n.º 2
0
 public static bool IsValidType(object value) => value == null || ReflectionHelpers.IsPrimitive(value.GetType()) || value is string || value is ParseObject || value is ParseACL || value is ParseFile || value is ParseGeoPoint || value is ParseRelationBase || value is DateTime || value is byte[] || ConversionHelpers.DowncastReference <IDictionary <string, object> >(value) != null || ConversionHelpers.DowncastReference <IList <object> >(value) != null;