private bool DeleteConfigSection(IPermissionActor target)
        {
            IConfigurationElement config = target is IPermissionGroup
                ? GroupsConfig["Groups"]
                : PlayersConfig[((IUser)target).UserType];

            List <PermissionSection> values = config.Get <PermissionSection[]>().ToList();
            int i = values.RemoveAll(c => c.Id.Equals(target.Id, StringComparison.OrdinalIgnoreCase));

            config.Set(values);
            return(i > 0);
        }
        public async Task <T> GetConfigSectionAsync <T>(IPermissionActor target, bool createIfNotFound) where T : PermissionSection
        {
            GuardTarget(target);

            bool isPermissionGroup = target is IPermissionGroup;

            IConfiguration config = null;
            string         path   = null;

            if (isPermissionGroup)
            {
                config = GroupsConfig;
                path   = "Groups";
            }
            else
            {
                config = PlayersConfig;
                path   = "Users";
            }

            if (createIfNotFound && !config.ChildExists(path))
            {
                config.CreateSection(path, SectionType.Array);
                await config.SaveAsync();
            }
            else if (!createIfNotFound && !config.ChildExists(path))
            {
                return(null);
            }

            IConfigurationElement configElement = config[path];

            if (configElement.Type != SectionType.Array)
            {
                throw new Exception("Expected array type but got " + configElement.Type);
            }

            List <PermissionSection> values = configElement.Get <PermissionSection[]>().ToList();

            if (!values.Any(c => c.Id.Equals(target.Id)))
            {
                if (!createIfNotFound)
                {
                    return(null);
                }

                PermissionSection toCreate;
                if (target is IPermissionGroup)
                {
                    toCreate = new GroupPermissionSection(target.Id, configElement);
                }
                else
                {
                    toCreate = new PlayerPermissionSection(target.Id, configElement);
                }

                await toCreate.SaveAsync();
            }

            T section = configElement.Get <T[]>().FirstOrDefault(c => c.Id == target.Id);

            section?.SetConfigElement(configElement);
            return(section);
        }