예제 #1
0
/// <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(Identification compareTo)
        {
            return(!this.IsTransient() && !compareTo.IsTransient() && this.Id.Equals(compareTo.Id));
        }
예제 #2
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 [Identification] instance to use as the destination.</param>
/// <returns>A copy of the object</returns>
        public virtual Identification Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, Identification copy = null)
        {
            if (copiedObjects == null)
            {
                copiedObjects = new Hashtable();
            }
            if (copy == null && copiedObjects.Contains(this))
            {
                return((Identification)copiedObjects[this]);
            }
            copy = copy ?? new Identification();
            if (!asNew)
            {
                copy.TransientId = this.TransientId;
                copy.Id          = this.Id;
            }
            copy.Number     = this.Number;
            copy.ExpiryDate = this.ExpiryDate;
            if (!copiedObjects.Contains(this))
            {
                copiedObjects.Add(this, copy);
            }
            if (deep && this.identificationType != null)
            {
                if (!copiedObjects.Contains(this.identificationType))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.IdentificationType = this.IdentificationType;
                    }
                    else if (asNew)
                    {
                        copy.IdentificationType = this.IdentificationType.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.identificationType = this.identificationType.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.IdentificationType = (IdentificationType)copiedObjects[this.IdentificationType];
                    }
                    else
                    {
                        copy.identificationType = (IdentificationType)copiedObjects[this.IdentificationType];
                    }
                }
            }
            if (deep && this.issuingCountry != null)
            {
                if (!copiedObjects.Contains(this.issuingCountry))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.IssuingCountry = this.IssuingCountry;
                    }
                    else if (asNew)
                    {
                        copy.IssuingCountry = this.IssuingCountry.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.issuingCountry = this.issuingCountry.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.IssuingCountry = (Country)copiedObjects[this.IssuingCountry];
                    }
                    else
                    {
                        copy.issuingCountry = (Country)copiedObjects[this.IssuingCountry];
                    }
                }
            }
            if (deep && this.person != null)
            {
                if (!copiedObjects.Contains(this.person))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.Person = this.Person;
                    }
                    else if (asNew)
                    {
                        copy.Person = this.Person.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.person = this.person.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.Person = (Person)copiedObjects[this.Person];
                    }
                    else
                    {
                        copy.person = (Person)copiedObjects[this.Person];
                    }
                }
            }
            return(copy);
        }