/// <summary> /// Returns true if self and the provided entity have the same Id values /// and the Ids are not of the default Id value /// </summary> protected bool HasSameNonDefaultIdAs(PostalAddress compareTo) { return(!this.IsTransient() && !compareTo.IsTransient() && this.Id.Equals(compareTo.Id)); }
/// <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 [PostalAddress] instance to use as the destination.</param> /// <returns>A copy of the object</returns> public virtual PostalAddress Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, PostalAddress copy = null) { if (copiedObjects == null) { copiedObjects = new Hashtable(); } if (copy == null && copiedObjects.Contains(this)) { return((PostalAddress)copiedObjects[this]); } copy = copy ?? new PostalAddress(); if (!asNew) { copy.TransientId = this.TransientId; copy.Id = this.Id; } copy.Province = this.Province; copy.Locality = this.Locality; copy.AddressLine1 = this.AddressLine1; copy.AddressLine2 = this.AddressLine2; copy.AddressLine3 = this.AddressLine3; copy.AddressNumber = this.AddressNumber; copy.PostalCode = this.PostalCode; copy.PostOfficeBoxNumber = this.PostOfficeBoxNumber; if (!copiedObjects.Contains(this)) { copiedObjects.Add(this, copy); } if (deep && this.addressType != null) { if (!copiedObjects.Contains(this.addressType)) { if (asNew && reuseNestedObjects) { copy.AddressType = this.AddressType; } else if (asNew) { copy.AddressType = this.AddressType.Copy(deep, copiedObjects, true); } else { copy.addressType = this.addressType.Copy(deep, copiedObjects, false); } } else { if (asNew) { copy.AddressType = (AddressType)copiedObjects[this.AddressType]; } else { copy.addressType = (AddressType)copiedObjects[this.AddressType]; } } } if (deep && this.timezone != null) { if (!copiedObjects.Contains(this.timezone)) { if (asNew && reuseNestedObjects) { copy.Timezone = this.Timezone; } else if (asNew) { copy.Timezone = this.Timezone.Copy(deep, copiedObjects, true); } else { copy.timezone = this.timezone.Copy(deep, copiedObjects, false); } } else { if (asNew) { copy.Timezone = (Timezone)copiedObjects[this.Timezone]; } else { copy.timezone = (Timezone)copiedObjects[this.Timezone]; } } } if (deep && this.city != null) { if (!copiedObjects.Contains(this.city)) { if (asNew && reuseNestedObjects) { copy.City = this.City; } else if (asNew) { copy.City = this.City.Copy(deep, copiedObjects, true); } else { copy.city = this.city.Copy(deep, copiedObjects, false); } } else { if (asNew) { copy.City = (City)copiedObjects[this.City]; } else { copy.city = (City)copiedObjects[this.City]; } } } copy.country = new List <Country>(); if (deep && this.country != null) { foreach (var __item in this.country) { if (!copiedObjects.Contains(__item)) { if (asNew && reuseNestedObjects) { copy.AddCountry(__item); } else { copy.AddCountry(__item.Copy(deep, copiedObjects, asNew)); } } else { copy.AddCountry((Country)copiedObjects[__item]); } } } return(copy); }