Ejemplo n.º 1
0
        /// <inheritdoc />
        public bool Remove(KeyValuePair <string, string> item)
        {
            if (item.Key == null)
            {
                throw new ArgumentException(
                          Resources.FormatPropertyOfTypeCannotBeNull(
                              nameof(KeyValuePair <string, string> .Key),
                              nameof(KeyValuePair <string, string>)),
                          nameof(item));
            }

            var index = Find(item.Key);

            if (index < 0)
            {
                return(false);
            }
            else if (string.Equals(item.Value, Get(index).Value, StringComparison.OrdinalIgnoreCase))
            {
                Remove(index);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public override void Contextualize(ViewContext viewContext)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException(nameof(viewContext));
            }

            if (viewContext.ViewData == null)
            {
                throw new ArgumentException(Resources.FormatPropertyOfTypeCannotBeNull(
                                                nameof(ViewContext.ViewData),
                                                typeof(ViewContext)),
                                            nameof(viewContext));
            }

            ViewData = viewContext.ViewData as ViewDataDictionary <TModel>;
            if (ViewData == null)
            {
                // viewContext may contain a base ViewDataDictionary instance. So complain about that type, not TModel.
                throw new ArgumentException(Resources.FormatArgumentPropertyUnexpectedType(
                                                nameof(ViewContext.ViewData),
                                                viewContext.ViewData.GetType().FullName,
                                                typeof(ViewDataDictionary <TModel>).FullName),
                                            nameof(viewContext));
            }

            base.Contextualize(viewContext);
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public void Add(KeyValuePair <string, string> item)
        {
            if (item.Key == null)
            {
                throw new ArgumentException(
                          Resources.FormatPropertyOfTypeCannotBeNull(
                              nameof(KeyValuePair <string, string> .Key),
                              nameof(KeyValuePair <string, string>)),
                          nameof(item));
            }

            var index = Find(item.Key);

            if (index < 0)
            {
                Insert(~index, item);
            }
            else
            {
                throw new InvalidOperationException(Resources.FormatDictionary_DuplicateKey(item.Key));
            }
        }