示例#1
0
        public static PersonColorPreferenceModel Parse([NotNull] string line, char delimiter)
        {
            var parts = line.Split(delimiter).ToSafeList().Select(l => l.Trim( )).ToList( );

            if (parts.Count != 5)
            {
                throw new InvalidOperationException( );
            }

            var lastName      = parts [0].NotNull( );
            var firstName     = parts [1].NotNull( );
            var gender        = parts [2].NotNull( );
            var favoriteColor = parts [3].NotNull( );
            var dateOfBirth   = parts [4].NotNull( );

            var record = new PersonColorPreferenceModel
            {
                LastName      = lastName,
                FirstName     = firstName,
                Gender        = gender,
                FavoriteColor = favoriteColor,
                DateOfBirth   = dateOfBirth
            };

            return(record);
        }
示例#2
0
        /// <summary>
        ///     Adds the specified modifiable.
        /// </summary>
        /// <param name="modifiable">The modifiable.</param>
        /// <returns>IPersonColorPreferenceModel.</returns>
        /// <inheritdoc />
        public int Add(IPersonColorPreferenceModel modifiable)
        {
            var copy  = new PersonColorPreferenceModel(modifiable);
            var newId = Interlocked.Increment(ref _recordsAdded);

            copy.Id = newId;

            _byId [newId] = copy;

            return(newId);
        }
示例#3
0
        public static PersonColorPreferenceModel GenerateRandomRecord([NotNull] Random randomProvider)
        {
            var dateTimeBirth = DateTime.Now.AddDays(0 - randomProvider.Next(0, 100 * 365));
            var dateOfBirth   = dateTimeBirth.ToPreferenceFormat( );

            string [] strings =
            {
                "Female",
                "Male"
            };

            var newRecord = new PersonColorPreferenceModel
            {
                FavoriteColor = RandomHelpers.RandomString(randomProvider, 3, 10, "color"),
                FirstName     = RandomHelpers.RandomString(randomProvider, 3, 10, "firstFirst"),
                LastName      = RandomHelpers.RandomString(randomProvider, 3, 10, "familyFamily'-"),
                DateOfBirth   = dateOfBirth,
                Gender        = strings [dateTimeBirth.Date.Day % 2].NotNull()
            };

            return(newRecord);
        }