コード例 #1
0
        public async Task <Brain> Light(IBulb bulb, int?intensity = null, int?autoDimBy = null)
        {
            if (Bulbs.Contains(bulb))
            {
                throw new ArgumentException(
                          $"Bulb '{bulb}' is already lighted.", nameof(bulb));
            }

            var adjustedBulb = await bulb.Adjust(intensity, autoDimBy);

            var nextBrain = await WithBulb(adjustedBulb);

            return(nextBrain);
        }
コード例 #2
0
        public async Task <Brain> Adjust(IBulb bulb, int?intensity = null, int?autoDimBy = null)
        {
            if (!Bulbs.Contains(bulb))
            {
                throw new ArgumentException(
                          $"Bulb '{bulb}' is not lighted.", nameof(bulb));
            }

            var adjustedBulb = await bulb.Adjust(intensity, autoDimBy);

            var shouldRemove = (adjustedBulb.Intensity <= 0);
            var nextBrain    =
                shouldRemove
                    ? await WithoutBulb(adjustedBulb)
                    : await WithBulbEvent(adjustedBulb);

            return(nextBrain);
        }