Example #1
0
        /// <summary>
        /// Tries to get a <see cref="IReadOnlyCollection{T}"/> of the specified <see cref="Player"/>'s <see cref="CustomRole"/>s.
        /// </summary>
        /// <param name="player">The player to check.</param>
        /// <param name="customRoles">The custom roles the player has.</param>
        /// <returns>True if the player has custom roles.</returns>
        /// <exception cref="ArgumentNullException">If the player is null.</exception>
        public static bool TryGet(Player player, out IReadOnlyCollection <CustomRole> customRoles)
        {
            if (player == null)
            {
                throw new ArgumentNullException(nameof(player));
            }

            List <CustomRole> tempList = ListPool <CustomRole> .Shared.Rent();

            tempList.AddRange(Registered?.Where(customRole => customRole.Check(player)) ?? Array.Empty <CustomRole>());

            customRoles = tempList.AsReadOnly();
            ListPool <CustomRole> .Shared.Return(tempList);

            return(customRoles?.Count > 0);
        }