Пример #1
0
/// <summary>
/// Copies the current object to a new instance
/// </summary>
/// <param name="deep">Copy members that refer to objects external to this class (not dependent)</param>
/// <param name="copiedObjects">Objects that should be reused</param>
/// <param name="asNew">Copy the current object as a new one, ready to be persisted, along all its members.</param>
/// <param name="reuseNestedObjects">If asNew is true, this flag if set, forces the reuse of all external objects.</param>
/// <param name="copy">Optional - An existing [Passenger] instance to use as the destination.</param>
/// <returns>A copy of the object</returns>
        public virtual Passenger Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, Passenger copy = null)
        {
            if (copiedObjects == null)
            {
                copiedObjects = new Hashtable();
            }
            if (copy == null && copiedObjects.Contains(this))
            {
                return((Passenger)copiedObjects[this]);
            }
            copy             = copy ?? new Passenger();
            copy.Accompanied = this.Accompanied;
            if (!copiedObjects.Contains(this))
            {
                copiedObjects.Add(this, copy);
            }
            copy.loyaltyCards = new List <LoyaltyCard>();
            if (deep && this.loyaltyCards != null)
            {
                foreach (var __item in this.loyaltyCards)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddLoyaltyCards(__item);
                        }
                        else
                        {
                            copy.AddLoyaltyCards(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddLoyaltyCards((LoyaltyCard)copiedObjects[__item]);
                    }
                }
            }
            if (deep && this.passengerCategory != null)
            {
                if (!copiedObjects.Contains(this.passengerCategory))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.PassengerCategory = this.PassengerCategory;
                    }
                    else if (asNew)
                    {
                        copy.PassengerCategory = this.PassengerCategory.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.passengerCategory = this.passengerCategory.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.PassengerCategory = (PassengerCategory)copiedObjects[this.PassengerCategory];
                    }
                    else
                    {
                        copy.passengerCategory = (PassengerCategory)copiedObjects[this.PassengerCategory];
                    }
                }
            }
            copy.postalAddress = new List <PostalAddress>();
            if (deep && this.postalAddress != null)
            {
                foreach (var __item in this.postalAddress)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddPostalAddress(__item);
                        }
                        else
                        {
                            copy.AddPostalAddress(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddPostalAddress((PostalAddress)copiedObjects[__item]);
                    }
                }
            }
            copy.discountCards = new List <DiscountCard>();
            if (deep && this.discountCards != null)
            {
                foreach (var __item in this.discountCards)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddDiscountCards(__item);
                        }
                        else
                        {
                            copy.AddDiscountCards(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddDiscountCards((DiscountCard)copiedObjects[__item]);
                    }
                }
            }
            copy.specialRequirements = new List <SpecialRequirement>();
            if (deep && this.specialRequirements != null)
            {
                foreach (var __item in this.specialRequirements)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddSpecialRequirements(__item);
                        }
                        else
                        {
                            copy.AddSpecialRequirements(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddSpecialRequirements((SpecialRequirement)copiedObjects[__item]);
                    }
                }
            }
            copy.creditCards = new List <CreditCard>();
            if (deep && this.creditCards != null)
            {
                foreach (var __item in this.creditCards)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddCreditCards(__item);
                        }
                        else
                        {
                            copy.AddCreditCards(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddCreditCards((CreditCard)copiedObjects[__item]);
                    }
                }
            }
            copy.pets = new List <Pet>();
            if (deep && this.pets != null)
            {
                foreach (var __item in this.pets)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddPets(__item);
                        }
                        else
                        {
                            copy.AddPets(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddPets((Pet)copiedObjects[__item]);
                    }
                }
            }
            copy.reservations = new List <Reservation>();
            if (deep && this.reservations != null)
            {
                foreach (var __item in this.reservations)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddReservations(__item);
                        }
                        else
                        {
                            copy.AddReservations(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddReservations((Reservation)copiedObjects[__item]);
                    }
                }
            }
            base.Copy(deep, copiedObjects, asNew, reuseNestedObjects, copy);
            return(copy);
        }