Exemplo n.º 1
0
        private void FlattenList(string parent, List <Tuple <string, string> > result, KeyValuePair <string, object> pair)
        {
            var index = 0;

            foreach (IResource IResource in pair.Value as IEnumerable)
            {
                result.AddRange(FlattenParameters(IResource.AsDictionary(), string.Concat(parent, "[", pair.Key, "][", index, "]")));
                index++;
            }
        }
Exemplo n.º 2
0
        internal List <Tuple <string, string> > FlattenParameters(IDictionary <string, object> parameters, string parent)
        {
            List <Tuple <string, string> > result = new List <Tuple <string, string> >();

            foreach (KeyValuePair <string, object> pair in parameters)
            {
                if (pair.Value is Dictionary <string, object> )
                {
                    result.AddRange(FlattenParameters((Dictionary <string, object>)pair.Value, string.Concat(parent, "[", pair.Key, "]")));
                }
                else if (pair.Value is IResource)
                {
                    IResource value = (IResource)pair.Value;
                    result.AddRange(FlattenParameters(value.AsDictionary(), string.Concat(parent, "[", pair.Key, "]")));
                }
                else if (pair.Value is List <IResource> )
                {
                    FlattenList(parent, result, pair);
                }
                else if (pair.Value is IList && pair.Value.GetType().GetGenericArguments().Single().GetInterfaces().Contains(typeof(IResource)))
                {
                    FlattenList(parent, result, pair);
                }
                else if (pair.Value is List <string> )
                {
                    List <string> list = (List <string>)pair.Value;
                    for (int i = 0; i < list.Count; i++)
                    {
                        result.Add(new Tuple <string, string>(string.Concat(parent, "[", pair.Key, "][", i, "]"), list[i]));
                    }
                }
                else if (pair.Value is List <Dictionary <string, object> > )
                {
                    List <Dictionary <string, object> > list = (List <Dictionary <string, object> >)pair.Value;
                    for (int i = 0; i < list.Count; i++)
                    {
                        result.AddRange(FlattenParameters(list[i], string.Concat(parent, "[", pair.Key, "][", i, "]")));
                    }
                }
                else if (pair.Value is DateTime)
                {
                    result.Add(new Tuple <string, string>(string.Concat(parent, "[", pair.Key, "]"), Convert.ToString(((DateTime)pair.Value).ToString("yyyy-MM-ddTHH:mm:sszzz"))));
                }
                else if (pair.Value != null)
                {
                    result.Add(new Tuple <string, string>(string.Concat(parent, "[", pair.Key, "]"), pair.Value.ToString()));
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        internal List <Tuple <string, string> > flattenParameters(IDictionary <string, object> parameters, string parent)
        {
            List <Tuple <string, string> > result = new List <Tuple <string, string> >();

            foreach (KeyValuePair <string, object> pair in parameters)
            {
                if (pair.Value is Dictionary <string, object> )
                {
                    result.AddRange(flattenParameters((Dictionary <string, object>)pair.Value, string.Concat(parent, "[", pair.Key, "]")));
                }
                else if (pair.Value is IResource)
                {
                    IResource value = (IResource)pair.Value;
                    result.AddRange(flattenParameters(value.AsDictionary(), string.Concat(parent, "[", pair.Key, "]")));
                }
                else if (pair.Value is List <IResource> )
                {
                    List <IResource> list = (List <IResource>)pair.Value;
                    for (int i = 0; i < list.Count; i++)
                    {
                        result.AddRange(flattenParameters(list[i].AsDictionary(), string.Concat(parent, "[", pair.Key, "][", i, "]")));
                    }
                }
                else if (pair.Value is List <Dictionary <string, object> > )
                {
                    List <Dictionary <string, object> > list = (List <Dictionary <string, object> >)pair.Value;
                    for (int i = 0; i < list.Count; i++)
                    {
                        result.AddRange(flattenParameters(list[i], string.Concat(parent, "[", pair.Key, "][", i, "]")));
                    }
                }
                else if (pair.Value != null)
                {
                    result.Add(new Tuple <string, string>(string.Concat(parent, "[", pair.Key, "]"), pair.Value.ToString()));
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        private object GetValue(PropertyInfo info)
        {
            object value = info.GetValue(this, null);

            if (value is IResource)
            {
                return(((IResource)value).AsDictionary());
            }

            if (value is IEnumerable <IResource> )
            {
                List <Dictionary <string, object> > values = new List <Dictionary <string, object> >();

                foreach (IResource IResource in (IEnumerable <IResource>)value)
                {
                    values.Add(IResource.AsDictionary());
                }

                return(values);
            }

            return(value);
        }