コード例 #1
0
        /// <summary>
        /// Supplementary method that discoveres Account instance type and converts to int (matches AccountType enum values).
        /// Will be used as AccountType property for AccountDTO object.
        /// </summary>
        /// <param name="account">
        /// Account instance.
        /// </param>
        /// <returns>
        /// Account type (int) for AccountDTO object constructor.
        /// </returns>
        private static int GetAccountType(Account account)
        {
            int accountType = -1;

            foreach (AccountType value in AccountType.GetValues(typeof(AccountType)))
            {
                if (account.GetType().Name == value.ToString())
                {
                    accountType = (int)value;
                    break;
                }
            }

            if (accountType < 0)
            {
                throw new ArgumentException(message: $"Unexpected account type - {account.GetType().ToString()}");
            }

            return(accountType);
        }