Exemplo n.º 1
0
        private static void PopulateDynamicResourceData(DynamicResult resource, NameValueCollection formData)
        {
            foreach (string name in formData.AllKeys)
            {
                string[] values = formData.GetValues(name);

                if (values == null || values.Length == 0)
                {
                    continue;
                }

                try
                {
                    if (values.Length == 1)
                    {
                        resource.Add(name, values[0]);
                    }
                    else
                    {
                        resource.Add(name, values);
                    }
                }
                catch (ArgumentException)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest, Global.InvalidDynamicPropertyName);
                }
            }
        }
        private static dynamic PopulateDynamicObject(IServiceContext context)
        {
            dynamic instance = new DynamicResult();

            foreach (string key in context.Request.QueryString.Keys)
            {
                IList<string> values = context.Request.QueryString.GetValues(key);
                string propertyName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(key);

                try
                {
                    if (values.Count == 1)
                    {
                        instance.Add(propertyName, values[0]);
                    }
                    else
                    {
                        instance.Add(propertyName, values);
                    }
                }
                catch (ArgumentException)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest, Global.InvalidDynamicPropertyName);
                }
            }

            return instance;
        }