private NamespaceSettingElement GetNamespaceSettingElement(
            DrapperConfigurationSection section,
            Type type)
        {
            foreach (NamespaceSettingElement setting in section.Namespaces)
            {
                var @namespace = type.Namespace;
                var periods    = @namespace.Count(x => x == '.');
                for (var i = periods; i > 0; i--)
                {
                    var entry = section.Namespaces[@namespace];
                    if (entry != null)
                    {
                        // we have a match.
                        return(entry);
                    }

                    @namespace = @namespace.Substring(0, @namespace.LastIndexOf('.'));
                }
            }
            return(null);
        }
        /// <summary>
        ///     Gets the command setting
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="key">The key.</param>
        public CommandSetting GetCommand(Type type, string key)
        {
            Require <ArgumentNullException>(type != null, ErrorMessages.NullTypePassed);
            Require <ArgumentNullException>(!string.IsNullOrWhiteSpace(key), ErrorMessages.NullKeyPassed);

            var section = DrapperConfigurationSection.GetConfiguration();

            Require <ArgumentNullException>(section != null, ErrorMessages.NoSectionDefinition);

            var @namespace = GetNamespaceSettingElement(section, type);

            Require <ArgumentNullException>(@namespace != null,
                                            ErrorMessages.NoNamespaceEntry,
                                            type.Namespace);

            var typeSetting = GetTypeSettingElement(@namespace, type);

            Require <ArgumentNullException>(typeSetting != null, ErrorMessages.UnknownType, type);

            var entry = GetCommandSetting(typeSetting, key);

            Require <ArgumentNullException>(entry != null, ErrorMessages.NoCommandSetting, type, key);

            var result = new CommandSetting
            {
                CommandText    = entry.CommandText,
                CommandTimeout = entry.CommandTimeout,
                CommandType    = entry.CommandType,
                Flags          = entry.Flags,
                Split          = entry.Split,
                IsolationLevel = entry.IsolationLevel
            };

            Validate(result);

            return(result);
        }