/// <summary>
 /// Copies all values from a (standalone) RVC back into this instance. This clears all values of this instance before.
 /// </summary>
 public void FromStandalone(IRouteValueCollection <T> standalone)
 {
     values.Clear();
     foreach (var val in standalone.Values)
     {
         values[val.Key] = val.Value;
     }
     Write();
 }
Exemple #2
0
        private void MoveDefaultTrack(IRouteValueCollection <string> property, Track current, int offset)
        {
            var idx = Tracks.IndexOf(current) + offset;

            if (idx < 0 || idx > Tracks.Count - 1)
            {
                return;
            }
            var next = Tracks[idx];

            property.SetValue(routeIndex, next.Name);
            Invalidate();
        }
        /// <summary>
        /// Returns a route value for the service method parameter or null.
        /// </summary>
        /// <param name="parameter">The service method parameter.</param>
        /// <param name="routeValues">The collection of route values.</param>
        /// <returns>The route value or null.</returns>
        protected virtual object TryGetRouteValue(ParameterInfo parameter, IRouteValueCollection routeValues)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }

            if (routeValues == null)
            {
                throw new ArgumentNullException("routeValues");
            }

            object routeValue = routeValues.TryGet(parameter.Name);

            if (routeValue == null)
            {
                return null;
            }

            object value;

            if (!SafeConvert.TryChangeType(routeValue, parameter.ParameterType, out value))
            {
                throw new HttpResponseException(HttpStatusCode.NotFound, Resources.Global.NotFound);
            }

            return value;
        }
Exemple #4
0
        private static void PopulateObjectValues(IRouteValueCollection source, NameValueCollection values)
        {
            if (source == null)
            {
                return;
            }

            foreach (string key in source.Keys)
            {
                var value = source.TryGet(key);

                if (value != null)
                {
                    values.Add(key, Convert.ToString(value, CultureInfo.InvariantCulture));
                }
            }
        }