Ejemplo n.º 1
0
        internal static LCObjectData Decode(IDictionary dict)
        {
            if (dict == null)
            {
                return(null);
            }
            LCObjectData objectData = new LCObjectData();

            foreach (DictionaryEntry kv in dict)
            {
                string key   = kv.Key.ToString();
                object value = kv.Value;
                if (key == "className")
                {
                    objectData.ClassName = value.ToString();
                }
                else if (key == "objectId")
                {
                    objectData.ObjectId = value.ToString();
                }
                else if (key == "createdAt" && DateTime.TryParse(value.ToString(), out DateTime createdAt))
                {
                    objectData.CreatedAt = createdAt;
                }
                else if (key == "updatedAt" && DateTime.TryParse(value.ToString(), out DateTime updatedAt))
                {
                    objectData.UpdatedAt = updatedAt;
                }
                else
                {
                    objectData.CustomPropertyDict[key] = LCDecoder.Decode(value);
                }
            }
            return(objectData);
        }
Ejemplo n.º 2
0
        public static async Task <object> RPC(string name, Dictionary <string, object> parameters = null)
        {
            string path = $"call/{name}";
            Dictionary <string, object> response = await LeanCloud.HttpClient.Post <Dictionary <string, object> >(path, data : parameters);

            return(LCDecoder.Decode(response["result"]));
        }
Ejemplo n.º 3
0
        private static object[] ParseParameters(MethodInfo mi, JsonElement body)
        {
            Dictionary <string, object> parameters = LCEngine.Decode(body);
            List <object> ps = new List <object>();

            if (mi.GetParameters().Length > 0)
            {
                if (Array.Exists(mi.GetParameters(),
                                 p => p.GetCustomAttribute <LCEngineFunctionParamAttribute>() != null))
                {
                    // 如果包含 LCEngineFunctionParamAttribute 的参数,则按照配对方式传递参数
                    foreach (ParameterInfo pi in mi.GetParameters())
                    {
                        LCEngineFunctionParamAttribute attr = pi.GetCustomAttribute <LCEngineFunctionParamAttribute>();
                        if (attr != null)
                        {
                            string paramName = attr.ParamName;
                            ps.Add(parameters[paramName]);
                        }
                    }
                }
                else
                {
                    ps.Add(LCDecoder.Decode(LCEngine.Decode(body)));
                }
            }

            return(ps.ToArray());
        }