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;
        }
Esempio n. 2
0
 public dynamic GetDynamicDict()
 {
     dynamic result = new DynamicResult();
     result.Name = new DynamicResult();
     result.Name.First = "Mike";
     result.Name.Last = "Hunt";
     result.Dat2 = new DateTime(2012, 12, 12);
     result.Url = new Uri("http://google.com?ab=c");
     return result;
 }
Esempio n. 3
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);
                }
            }
        }