예제 #1
0
        public void ExecuteCommand(IList <string> tokens)
        {
            IWeapon  currentWeapon = null;
            IBaseGem currentGem    = null;

            string commandName = tokens[0];

            switch (commandName)
            {
            case "Create":
                List <string> weaponInfo = inHandler.SplitInput(tokens[1], " ");
                weaponInfo.Add(tokens[2]);
                this.weapons.Add(this.weaponFactory.Create(weaponInfo));
                break;

            case "Add":
                currentWeapon = GetWeapon(tokens[1]);
                currentGem    = this.gemFactory.Create(inHandler.SplitInput(tokens[3], " "));

                currentWeapon.AddGem(int.Parse(tokens[2]), currentGem);
                break;

            case "Remove":
                currentWeapon = GetWeapon(tokens[1]);
                currentWeapon.RemoveGem(int.Parse(tokens[2]));
                break;

            case "Print":
                currentWeapon = GetWeapon(tokens[1]);
                outHandler.PrintLine(currentWeapon.ToString());
                break;

            case "Author":
                outHandler.PrintLine(weaponAttribute.PrintInfo("Author"));
                break;

            case "Revision":
                outHandler.PrintLine(weaponAttribute.PrintInfo("Revision"));
                break;

            case "Description":
                outHandler.PrintLine(weaponAttribute.PrintInfo("Description"));
                break;

            case "Reviewers":
                outHandler.PrintLine(weaponAttribute.PrintInfo("Reviewers"));
                break;

            default:
                throw new InvalidOperationException($"Command not available: {commandName}");
            }
        }
예제 #2
0
        public override string Execute()
        {
            var field = this.data[0];

            var             weaponAtr    = typeof(Weapon).GetCustomAttributes(false).FirstOrDefault();
            WeaponAttribute fieldToPrint = (WeaponAttribute)weaponAtr;

            var result = fieldToPrint.PrintInfo(field);

            return(result);
        }
예제 #3
0
        static void Main()
        {
            var input = Console.ReadLine();

            var             testAttribute = typeof(Weapon);
            var             atr           = testAttribute.GetCustomAttributes(false).FirstOrDefault();
            WeaponAttribute a             = (WeaponAttribute)atr;

            while (input != "END")
            {
                Console.WriteLine(a.PrintInfo(input));

                input = Console.ReadLine();
            }
        }