Example #1
0
        public static IDictionary <string, object> GetNamedArgs(this InvokeMemberBinder binder, object[] args)
        {
            var ret             = new Dictionary <string, object>();
            int unnamedArgCount = binder.UnnamedArgCount();

            for (int i = 0; i < binder.CallInfo.ArgumentNames.Count; i++)
            {
                var arg = args[i + unnamedArgCount];
                if (arg != null) // filter out null parameters
                {
                    ret.Add(binder.CallInfo.ArgumentNames[i], arg);
                }
            }
            return(ret);
        }
Example #2
0
        public RestRequest BuildRequest(InvokeMemberBinder binder, object[] args)
        {
            Debug.Assert(binder.IsVerb());

            // total number of segments is the number or parts of the call chain not including the root
            // example: proxy.location.geo.get() has two url segments - the verb doesn't count
            // Index is zero based so add one
            string template = CreateUrlSegmentTemplate(_proxy.Index + 1);

            var request = new RestRequest(template);

            request.RequestFormat = DataFormat.Json; // we only talk json
            request.AddHeader("Accept", "application/json, text/json, text/x-json, text/javascript");

            // fill in the url segments with the names of each call chain member
            _proxy.AddSegment(request); // this recurses up the instance chain

            int unnamedArgCount = binder.UnnamedArgCount();

            // all named arguments are added as parameters
            for (int i = 0; i < binder.CallInfo.ArgumentNames.Count; i++)
            {
                var arg = args[i + unnamedArgCount];
                if (arg is IDictionary <string, object> ) // if the arg is a dictionary, add each item as a parameter key value pair
                {
                    request.AddDictionary((IDictionary <string, object>)arg);
                }
                else
                {
                    request.AddParameter(binder.CallInfo.ArgumentNames[i].TrimStart(_proxy.KeywordEscapeCharacter), arg);
                }
            }

            // all unnamed args get added to the request body
            for (int i = 0; i < unnamedArgCount; i++)
            {
                request.AddBody(args[i]);
            }

            return(request);
        }
Example #3
0
        internal static readonly string[] _verbs = new string[] { "post", "get", "delete", "put", "patch" }; // currently supported verbs

        public static IEnumerable <object> GetUnnamedArgs(this InvokeMemberBinder binder, object[] args)
        {
            return(args.Take(binder.UnnamedArgCount()).Where(o => o != null)); // filter out nulls
        }