Ejemplo n.º 1
0
        /// <summary>
        /// Gets a list of <see cref="CelestialObject"/> for a <see cref="CelestialObjectType.Planet"/>
        /// </summary>
        /// <param name="solarSystemObject">Parse a <see cref="CelestialObject"/> of type <see cref="CelestialObjectType.Planet"/></param>
        /// <param name="includeMinorMoons">If true <see cref="CelestialObjectType.MinorMoon"/> are included.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException">If <see cref="solarSystemObject"/> is not of type <see cref="CelestialObjectType.Planet"/>.</exception>
        private static IEnumerable <CelestialObject> GetMoons(this CelestialObject solarSystemObject, bool includeMinorMoons)
        {
            if (solarSystemObject.GetSolarSystemObjectType() != CelestialObjectType.Planet)
            {
                throw new ArgumentException($"{solarSystemObject} is not of type {CelestialObjectType.Planet}.", nameof(solarSystemObject));
            }

            var solarSolarSystemObjectTypes = new List <CelestialObjectType> {
                CelestialObjectType.MajorMoon
            };

            if (includeMinorMoons)
            {
                solarSolarSystemObjectTypes.Add(CelestialObjectType.MinorMoon);
            }

            bool Expression(CelestialObject x) =>
            x > solarSystemObject &&
            x < solarSystemObject + (int)CelestialObjectType.Planet &&
            x.GetSolarSystemObjectType().In(solarSolarSystemObjectTypes.ToArray());

            return(EnumHelper.GetValues((Func <CelestialObject, bool>)Expression));
        }