Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

adbaga / Ics0016-2019f

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • Ics0016-2019f
  • MenuSystem
  • MenuItem.cs
Find file
BlameHistoryPermalink
  • adbaga's avatar
    Initial commit Minesweeper · fe48d7ed
    adbaga committed 5 years ago
    fe48d7ed
MenuItem.cs 1.08 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
using System;

namespace MenuSystem
{
    public class MenuItem
    {
        private string _title;

        public string Title
        {
            get => _title;
            set => _title = Validate(value, 1, 100, false);
        }


        // reference to an method, which returns a string and takes no parameters
        // func<...parameter types..., return type>
        public Func<string> CommandToExecute { get; set; }
        
        private static string Validate(string item, int minLength, int maxLength, bool toUpper)
        {
            item = item.Trim();
            if (toUpper)
            {
                item = item.ToUpper();
            }
            if (item.Length < minLength  || item.Length > maxLength)
            {
                throw new ArgumentException(
                    $"String is not correct length (" +
                    $"{minLength}-{maxLength})! Got " +
                    $"{item.Length} characters.");
            }

            return item;
        }

        public override string ToString()
        {
            return Title;
        }
    }
}