/// <summary> /// Determines whether two reference entities are semantically equivalent (whether they represent the same value). /// </summary> /// <param name="x">The first reference entity to compare.</param> /// <param name="y">The second reference entity to compare.</param> /// <returns>True when entities are semantically equivalent, false otherwise.</returns> public bool Equals(IStonReferenceEntity x, IStonReferenceEntity y) { if (x == y) { return(true); } else if (x == null || y == null) { return(false); } IStonValuedEntity xval, yval; xval = Document.GetReferencedValue(x); yval = Document.GetReferencedValue(y); if (xval == null || yval == null) { return(false); } else { return(Equals(xval, yval)); } }
/// <summary> /// Creates a structurally equivalent reference entity from a given entity. /// </summary> /// <param name="entity">The entity to copy the structure of.</param> /// <returns>A structurally equivalent copy of the given entity.</returns> public static IStonReferenceEntity Copy(IStonReferenceEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } return(new StonReferenceEntity(entity)); }
/// <summary> /// Returns a hash code for a given reference entity, applied to entities semantic equivalence. /// It is the same as its referenced value hash code. /// </summary> /// <param name="obj">The reference entity to get a hash code of.</param> /// <returns>The hash code for the entity.</returns> public int GetHashCode(IStonReferenceEntity obj) { if (obj == null) { return(0); } return(GetHashCode(Document.GetReferencedValue(obj))); }
/// <summary> /// Checks a validity of a given STON reference entity. /// </summary> /// <param name="entity">The entity to check the validity of.</param> public static void ValidateEntity(IStonReferenceEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } try { if (entity.GlobalIdentifier != null) { ValidateGlobalIdentifier(entity.GlobalIdentifier); } if (entity.Address == null) { throw new StonException("A reference entity cannot have a non-existing address."); } ValidateAddress(entity.Address); } catch (StonException ex) { throw new StonReferenceException(entity, ex.Message); } }
/// <summary> /// Creates a structurally equivalent reference entity from a given entity. /// </summary> /// <param name="entity">The entity to copy the structure of.</param> public StonReferenceEntity(IStonReferenceEntity entity) : this(entity.Address, entity.GlobalIdentifier) { }
// writes a reference entity private void WriteEntity(StonTokenWriter writer, IStonReferenceEntity entity) { WriteGlobalIdentifier(writer, entity.GlobalIdentifier); WriteReferenceAddress(writer, entity.Address); }