internal IEnumerable <T> Get <T>(string[] path, int pos, bool attempt_conversion)
        {
            string key = path[pos];
            int    index;

            // The key is an index; otherwise ignore
            if (key[0] == '[' && key[key.Length - 1] == ']')
            {
                // The key refers to all items ("[*]")
                if (key.Length == 3 && key[1] == '*')
                {
                    foreach (var item in _array)
                    {
                        foreach (var value in GSObject.Get <T>(path, pos, item, attempt_conversion))
                        {
                            yield return(value);
                        }
                    }
                }

                // The key is a specific index (e.g. "[2]") and within the array bounds
                else if (int.TryParse(key.Substring(1, key.Length - 2), out index) && index < Length)
                {
                    foreach (var value in GSObject.Get <T>(path, pos, _array[index], attempt_conversion))
                    {
                        yield return(value);
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Gets one or more nested objects.
 /// </summary>
 ///
 /// <typeparam name="T">The type of the object(s) to obtain. Can be either of: bool, bool?, int, int?, long,
 /// long?, decimal, decimal?, string, GSObject, GSArray. Note that if the object(s) pointed to by the path do
 /// not match this type, they won't be returned unless attempt_conversion was set to true. Also note that if
 /// the response contains a null value and you request a non-nullable data type (bool, int, etc) then that
 /// response value will be ignored. If you do request a nullable or class type (int?, GSObject, etc) then a
 /// null object will be returned.</typeparam>
 ///
 /// <param name="path">A dot-delimited path down the objects hierarchy. You can access specific array items
 /// using bracket notation ([]). The brackets can specify an explicit index or '*' to traverse all elements.
 /// For example, if you call the socialize.exportUsers method (see http://developers.gigya.com/037_API_reference/020_REST_API/socialize.exportUsers),
 /// then the path "users[0].identities[0].provider" will return a list with a single item being the first user's
 /// first social provider. The path "users[*].UID" will return a list containing the UID field in each object in
 /// the users array.</param>
 ///
 /// <param name="attempt_conversion">If true, and if you requested string results, then the internal response
 /// objects will be converted to strings (e.g. 2 --> "2"). This includes arrays and compound objects. If you
 /// requested a primitive type, a parse operation will be attempted (e.g. "2" --> 2).</param>
 ///
 /// <returns>A list of values which match the path and whose type matches the template parameter.</returns>
 public IEnumerable <T> Get <T>(string path, bool attempt_conversion = false)
 {
     if (data == null)
     {
         throw new GSResponseNotInitializedException();
     }
     else
     {
         return(data.Get <T>(TokenizePath(path), 0, attempt_conversion));
     }
 }