Exemplo n.º 1
0
        private void ConstructFromJSONString(JSONObject jsonObj)
        {
            string key;
            object value;

            foreach (KeyValuePair <string, object> kvp in jsonObj)
            {
                key   = kvp.Key;
                value = kvp.Value;

                if (value == null)
                {
                    this.Put(key, value); // null values are allowed
                }
                else if (value is decimal)
                {
                    this.Put(key, (double)(decimal)value);
                }
                else if (value.GetType().IsPrimitive || value is string)
                {
                    this.Put(key, value);
                }
                else if (value is JSONObject) // value itself is a json object
                {
                    // Create a new GSObject to put as the value of the current key. the source for this child is the current value
                    GSObject child = new GSObject((JSONObject)value);
                    this.Put(key, child);
                }
                else if (value is JSONArray) // value is an array
                {
                    GSArray childArray = new GSArray((JSONArray)value);
                    this.Put(key, childArray);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns the value to which the specified key inside the response params is associated with, or defaultValue
 /// if the response params does not contain such a key.
 /// </summary>
 /// <param name="key">the key whose associated value is to be returned.
 /// The key can specify a dot-delimited path down the objects hierarchy, with brackets to access array items.
 /// For example, "users[0].identities[0].provider" (see socialize.exportUsers API).</param>
 /// <param name="defaultValue">the value to be returned if the request params doesn't contain the specified key.</param>
 /// <returns>the value to which the specified key is mapped, or the defaultValue if the request params
 /// does not contain such a key</returns>
 public GSArray GetArray(string key, GSArray defaultValue)
 {
     if (data == null)
     {
         throw new GSResponseNotInitializedException();
     }
     return(this.data.GetArray(key, defaultValue));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Associates the specified value with the specified key in this dictionary.
 /// If the dictionary previously contained a mapping for the key, the old value is replaced by the specified value.
 /// </summary>
 /// <param name="key">key with which the specified value is to be associated</param>
 /// <param name="value">a GSObject[] value to be associated with the specified key</param>
 public GSObject Put(string key, GSArray value)
 {
     if (key != null)
     {
         this._map[key] = value;
     }
     return(this);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the GSObject[] value to which the specified key is mapped, or the defaultValue
        /// if this dictionary contains no mapping for the key.
        /// </summary>
        /// <param name="key">the key whose associated value is to be returned</param>
        /// <param name="defaultValue">the GSObject[] value to be returned if this dictionary doesn't contain the specified key.</param>
        /// <returns>the GSObject[] value to which the specified key is mapped, or the defaultValue if this
        /// dictionary contains no mapping for the key</returns>
        public GSArray GetArray(string key, GSArray defaultValue)
        {
            GSArray retVal = defaultValue;

            try { retVal = this.GetTypedObject(key, defaultValue, true); }
            catch { }

            return(retVal);
        }
Exemplo n.º 5
0
        private void ReflectObject(object clientParams)
        {
            Type clientParamsType     = clientParams.GetType();
            List <MemberInfo> members = GetTypeMembers(clientParamsType);

            foreach (MemberInfo member in members)
            {
                object value = GetMemberValue(clientParams, member);

                String memberName = member.Name;
                if (null == value)
                {
                    this.Put(memberName, value);
                }
                else
                {
                    Type type = value.GetType();
                    if (type.IsPrimitive || type == typeof(String))
                    {
                        this.Put(memberName, value);
                    }
                    else if (value is IEnumerable)
                    {
                        IEnumerable enu   = value as IEnumerable;
                        GSArray     gsArr = new GSArray();
                        foreach (object obj in enu)
                        {
                            if (null == obj)
                            {
                                gsArr.Add(null as Object);
                            }
                            else
                            {
                                Type arrItemType = obj.GetType();
                                if (arrItemType == typeof(String) || arrItemType.IsPrimitive)
                                {
                                    gsArr.Add(obj);
                                }
                                else
                                {
                                    GSObject gsObjArrItem = new GSObject(obj);
                                    gsArr.Add(gsObjArrItem);
                                }
                            }
                        }
                        this.Put(memberName, gsArr);
                    }

                    else if (type.IsClass)
                    {
                        value = new GSObject(value);
                        this.Put(memberName, value);
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds XML node as a dictionary entry
        /// </summary>
        /// <param name="node">the node to convert</param>
        /// <param name="dic">the GSObject to add the converted node to</param>
        private void XmlToDictionaryEntry(XmlElement node, GSObject dic)
        {
            // Build a sorted list of key-value pairs
            //  where   key is case-sensitive nodeName
            //          value is an ArrayList of string or XmlElement
            //  so that we know whether the nodeName is an array or not.
            SortedList childNodeNames = new SortedList();

            //  Add in all nodes
            foreach (XmlNode cnode in node.ChildNodes)
            {
                if (cnode is XmlText)
                {
                    StoreChildNode(childNodeNames, "value", cnode.InnerText);
                }
                else if (cnode is XmlElement)
                {
                    StoreChildNode(childNodeNames, cnode.Name, cnode);
                }
            }

            foreach (string childname in childNodeNames.Keys)
            {
                ArrayList alChild = (ArrayList)childNodeNames[childname];
                if (alChild.Count == 1)
                {
                    OutputNode(childname, alChild[0], dic, true);
                }
                else
                {
                    GSArray arr = new GSArray();
                    dic.Put(node.Name, arr);
                    for (int i = 0; i < alChild.Count; i++)
                    {
                        GSObject cDic = new GSObject();
                        OutputNode(null, alChild[i], cDic, false);
                        arr[i] = cDic;
                    }
                    dic.Put(childname, arr);
                }
            }
        }
Exemplo n.º 7
0
 internal GSArray(JSONArray jsonArray)
 {
     for (int i = 0; i < jsonArray.Count; i++)
     {
         object value = jsonArray[i];
         if (value is JSONObject)
         {
             GSObject obj = new GSObject((JSONObject)value);
             _array.Add(obj);
         }
         else if (value is JSONArray)
         {
             GSArray arr = new GSArray((JSONArray)value);
             _array.Add(arr);
         }
         else
         {
             _array.Add(value);
         }
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Returns the GSObject[] value to which the specified key is mapped.
        /// </summary>
        /// <param name="key">the key whose associated value is to be returned</param>
        /// <returns>the GSObject[] value to which the specified key is mapped.</returns>
        /// <exception cref="Gigya.Socialize.SDK.GSKeyNotFoundException">thrown if the key is not found</exception>
        /// <exception cref="System.InvalidCastException">thrown if the value cannot be cast to GSObject[]</exception>
        public GSArray GetArray(string key)
        {
            GSArray retVal = this.GetTypedObject <GSArray>(key, null, false);

            return(retVal);
        }
Exemplo n.º 9
0
        /* GET GSOBJECT[] */
        public IEnumerable <T> GetArray <T>(string key) where T : class, new()
        {
            GSArray array = GetArray(key);

            return(array.Cast <T>());
        }
Exemplo n.º 10
0
 public void Add(GSArray val)
 {
     _array.Add(val);
 }
Exemplo n.º 11
0
        public IEnumerable <T> GetArray <T>(int index) where T : class, new()
        {
            GSArray array = GetArray(index);

            return(array.Cast <T>());
        }