Пример #1
0
        public Dog(SerializationInfo info, StreamingContext ctxt) : base(info, ctxt)
        {
            SimpleDate lastWalkDate = (SimpleDate)info.GetValue("LastWalkDate", typeof(SimpleDate));

            if (lastWalkDate != null)
            {
                if (SimpleDate.Compare(lastWalkDate, base.DateOfBirth) >= 0 &&
                    SimpleDate.Compare(lastWalkDate,
                                       new SimpleDate(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year)) <
                    0)
                {
                    throw new ArgumentException("The dog's lastwalkdate is before birthday or after today.");
                }
                LastWalkDate = lastWalkDate;
            }
        }
Пример #2
0
 /// <summary>
 /// Creates a dog.
 /// </summary>
 /// <param name="chipRegistrationNumber">The chipnumber of the animal.
 ///                                      Must be unique. Must be zero or greater than zero.</param>
 /// <param name="dateOfBirth">The date of birth of the animal.</param>
 /// <param name="name">The name of the animal.</param>
 /// <param name="lastWalkDate">The date of the last walk with the dog or null if unknown.</param>
 public Dog(int chipRegistrationNumber, SimpleDate dateOfBirth,
            string name, SimpleDate lastWalkDate) : base(chipRegistrationNumber, dateOfBirth, name)
 {
     if (lastWalkDate != null)
     {
         if (SimpleDate.Compare(lastWalkDate, dateOfBirth) < 0 &&
             SimpleDate.Compare(lastWalkDate,
                                new SimpleDate(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year)) >=
             0)
         {
             LastWalkDate = lastWalkDate;
         }
         else
         {
             throw new ArgumentException("The dog's lastwalkdate is before birthday or after today.");
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Creates an animal.
        /// </summary>
        /// <param name="chipRegistrationNumber">The chipnumber of the animal.
        ///                                      Must be unique. Must be zero or greater than zero.</param>
        /// <param name="dateOfBirth">The date of birth of the animal.</param>
        /// <param name="name">The name of the animal.</param>
        public Animal(int chipRegistrationNumber, SimpleDate dateOfBirth, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Invalid name");
            }


            if (chipRegistrationNumber <= 0)
            {
                throw new ArgumentException("Chipnumber wrong");
            }

            if (dateOfBirth == null || SimpleDate.Compare(dateOfBirth, new SimpleDate(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year)) <= 0)
            {
                throw new ArgumentException("Date of birth is of the wrong type or later than today");
            }
            DateOfBirth = dateOfBirth;

            Name = name;
            ChipRegistrationNumber = chipRegistrationNumber;
            IsReserved             = false;
        }