Ejemplo n.º 1
0
        static string AppendTo(string value, string separateChar, object routes)
        {
            var dictionary = AnonymousHelper
                             .ToDictionary(routes)
                             .Where(r => r.Value != null)
                             .Select(r =>
            {
                string switcherValue = r.Value is Selector ?
                                       r.Value.ToString().Replace("&", "%26")
                                       .Replace("?", "%3F")
                                       .Replace("/", "%2F")
                                       .Replace("=", "%3D")
                                       .Replace(":", "%3A")
                                       .Replace("@", "%40")
                                       .Replace("#", "%23")
                                                               : r.Value.ToString();
                return(new KeyValuePair <string, string>(r.Key, switcherValue));
            })
                             .ToDictionary(r => r.Key, r => r.Value);

            if (dictionary.Count == 0)
            {
                return(value);
            }

            bool hasExistsQueryString = (value ?? string.Empty).Contains("?");

            if (hasExistsQueryString)
            {
                var originalQuery = value.Split("?".ToCharArray(), 2)[1]
                                    .Split(separateChar.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                                    .Select(r =>
                {
                    var pair = r.Split("=".ToCharArray(), 2);
                    return(new KeyValuePair <string, string>(pair.ElementAtOrDefault(0), pair.ElementAtOrDefault(1)));
                })
                                    .ToDictionary(r => r.Key, r => r.Value);

                foreach (var newParam in dictionary)
                {
                    originalQuery.Set(newParam);
                }

                dictionary = originalQuery;
                value      = value.Substring(0, value.IndexOf("?", StringComparison.CurrentCultureIgnoreCase));
            }

            string hashRoutes = string.Join(separateChar, dictionary.Select(r => string.Format("{0}={1}", HttpUtility.UrlEncode(r.Key), dictionary[r.Key])));

            return(value != null ? "{0}?{1}".F(value, hashRoutes)
                           : hashRoutes);
        }
        public static void Merge(this IDictionary <string, object> src, object dest)
        {
            var dictionaryFromAnonymous = AnonymousHelper.ToDictionary(dest);

            Core.Extensions.DictionaryExtensions.Merge(src, dictionaryFromAnonymous);
        }