コード例 #1
0
        // Todo: Resolve
        private static void BruteForceValues(
            Result <Animal> probablyAnAnimal,
            Result <AnimalSafetyRules> probablyRules,
            Result <bool> probablyDietInfo,
            Result <Guid> probablyuserId,
            Result <decimal> probablyTicketPrice)
        {
            bool somethingFailed = false;

            Animal animal = probablyAnAnimal.Resolve(x => x, e => { somethingFailed = true; return(new Animal {
                    Dangerous = Animal.DangerClass.Undefined, Name = "Dummy"
                }); });

            if (!somethingFailed)
            {
                AnimalSafetyRules rules = probablyRules.Resolve(x => x, e => { somethingFailed = true; return(new AnimalSafetyRules("Dummy", DangerLevel.Benign)); });
                if (!somethingFailed)
                {
                    bool isCarnivore = probablyDietInfo.Resolve(x => x, e => { somethingFailed = true; return(false); });
                    if (!somethingFailed)
                    {
                        Guid g = probablyuserId.Resolve(x => x, e => { somethingFailed = true; return(Guid.Empty); });
                        if (!somethingFailed)
                        {
                            decimal price = probablyTicketPrice.Resolve(x => x, e => { somethingFailed = true; return(-1m); });
                            if (!somethingFailed)
                            {
                                var    result  = BusinessLogic(animal, rules, isCarnivore, g, price);
                                string summary = $"All went well!\n\n{result}";
                                Console.WriteLine(summary);
                            }
                            else
                            {
                                Console.WriteLine("Calculation failed: Unable to communicate with invoice and ticket systems.");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Calculation failed: User not located.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Calculation failed: Safety procedure rules not located.");
                    }
                }
                else
                {
                    Console.WriteLine("Calculation failed: Carnivore status undetermined.");
                }
            }
            else
            {
                Console.WriteLine("Calculation failed: Retrievel of the animal failed.");
            }
        }
コード例 #2
0
        private static string BusinessLogic(Animal animal, AnimalSafetyRules animalAnimalSafetyRules, bool carnivore, Guid userId, decimal ticketPrice)
        {
            var sb   = new StringBuilder();
            var glue = carnivore ? "is" : "is not";

            sb.AppendLine($"*** Animal Facts about {animal.Name} ***");
            sb.AppendLine($"A word of caution. This animal is classed as Danger Level '{animalAnimalSafetyRules.CautionLevel}', because {animalAnimalSafetyRules.SafetyRules}.");
            sb.AppendLine($"It {glue} a carnivorous animal.");
            sb.AppendLine($"Information about {animal.Name}, such as its wight, {animal.WeightInKilograms} kg, was last updated by user id {userId}.");
            sb.AppendLine($"Ticket price to see {animal.Name}: kr. {ticketPrice}");

            return(sb.ToString());
        }