public static void AddVerb(VerbElement verb, RequestFilteringSection section)
        {
            if (verb == null)
            {
                throw new ArgumentNullException("verb");
            }
            if (verb.Verb == null)
            {
                throw new ArgumentNullException("verb.Verb");
            }

            VerbCollection collection = section.Verbs;

            if (collection.Any(v => v.Verb.Equals(verb.Verb)))
            {
                throw new AlreadyExistsException("verb");
            }

            try {
                collection.Add(verb);
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }
        }
        public static void DeleteVerb(VerbElement verb, RequestFilteringSection section)
        {
            if (verb == null)
            {
                return;
            }

            VerbCollection collection = section.Verbs;

            // To utilize the remove functionality we must pull the element directly from the collection
            verb = collection.FirstOrDefault(v => v.Verb.Equals(verb.Verb));

            if (verb != null)
            {
                try {
                    collection.Remove(verb);
                }
                catch (FileLoadException e) {
                    throw new LockedException(section.SectionPath, e);
                }
                catch (DirectoryNotFoundException e) {
                    throw new ConfigScopeNotFoundException(e);
                }
            }
        }
        public static VerbElement CreateVerb(dynamic model, RequestFilteringSection section)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            string verbString = DynamicHelper.Value(model.verb);

            if (string.IsNullOrEmpty(verbString))
            {
                throw new ApiArgumentException("verb");
            }

            VerbElement verb = section.Verbs.CreateElement();

            verb.Verb = verbString;

            UpdateVerb(verb, model);

            return(verb);
        }
        public static VerbElement UpdateVerb(VerbElement verb, dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (verb == null)
            {
                throw new ArgumentNullException("verb");
            }

            try {
                verb.Allowed = DynamicHelper.To <bool>(model.allowed) ?? verb.Allowed;
            }
            catch (FileLoadException e) {
                throw new LockedException(RequestFilteringGlobals.RequestFilteringSectionName, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }

            return(verb);
        }
        public static void UpdateFeatureSettings(dynamic model, RequestFilteringSection section)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (section == null)
            {
                throw new ArgumentNullException("section");
            }

            try {
                DynamicHelper.If <bool>((object)model.allow_unlisted_file_extensions, v => section.FileExtensions.AllowUnlisted = v);
                DynamicHelper.If <bool>((object)model.allow_unlisted_verbs, v => section.Verbs.AllowUnlisted         = v);
                DynamicHelper.If <bool>((object)model.allow_high_bit_characters, v => section.AllowHighBitCharacters = v);
                DynamicHelper.If <bool>((object)model.allow_double_escaping, v => section.AllowDoubleEscaping        = v);
                DynamicHelper.If((object)model.max_content_length, 0, uint.MaxValue, v => section.RequestLimits.MaxAllowedContentLength = v);
                DynamicHelper.If((object)model.max_url_length, 0, uint.MaxValue, v => section.RequestLimits.MaxUrl = v);
                DynamicHelper.If((object)model.max_query_string_length, 0, uint.MaxValue, v => section.RequestLimits.MaxQueryString = v);

                // Verbs
                if (model.verbs != null)
                {
                    IEnumerable <dynamic> verbs = (IEnumerable <dynamic>)model.verbs;


                    List <VerbElement> verbList = new List <VerbElement>();

                    // Validate all verbs provided
                    foreach (dynamic verb in verbs)
                    {
                        if (verb.name == null)
                        {
                            throw new ApiArgumentException("verb.name");
                        }
                        if (verb.allowed == null)
                        {
                            throw new ApiArgumentException("verb.allowed");
                        }

                        string name    = DynamicHelper.Value(verb.name);
                        bool   allowed = DynamicHelper.To <bool>(verb.allowed);

                        VerbElement newVerb = section.Verbs.CreateElement();

                        newVerb.Allowed = allowed;
                        newVerb.Verb    = name;

                        // Add to temp list
                        verbList.Add(newVerb);
                    }

                    // Clear configuration's collection
                    section.Verbs.Clear();

                    // Move from temp list to the configuration's collection
                    verbList.ForEach(v => section.Verbs.Add(v));
                }

                if (model.metadata != null)
                {
                    DynamicHelper.If <OverrideMode>((object)model.metadata.override_mode, v => section.OverrideMode = v);
                }
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }
        }