/// <summary> /// Checks the validity of a given STON reference address. /// </summary> /// <param name="address">The reference address to check the validity of.</param> public static void ValidateAddress(IStonAddress address) { if (address == null) { throw new ArgumentNullException("address"); } if (address.InitialContext == null) { throw new StonException("A reference address cannot have a non-existing initial context."); } if (address.RelativePath == null) { throw new StonException("A reference address cannot have a non-existing relative path."); } ValidateInitialContext(address.InitialContext); foreach (var segment in address.RelativePath) { if (segment == null) { throw new StonException("A reference address relative path cannot have non-existing path segments."); } ValidatePathSegment(segment); } }
/// <summary> /// Creates a structurally equivalent STON address from a given address. /// </summary> /// <param name="address">The address to copy the structure of.</param> /// <returns>A structurally equivalent copy of the given address.</returns> public static IStonAddress Copy(IStonAddress address) { if (address == null) { throw new ArgumentNullException("address"); } return(new StonAddress(address)); }
/// <summary> /// Creates a new reference entity, with a given reference address and optional global identifier. /// </summary> /// <param name="address">The address of the referenced value.</param> /// <param name="globalIdentifier">The global identifier of the entity.</param> public StonReferenceEntity(IStonAddress address, string globalIdentifier = null) : base(globalIdentifier) { if (address == null) { throw new ArgumentNullException("address"); } Address = StonAddress.Copy(address); Helpers.Validator.ValidateEntity(this); }
// writes a reference address private void WriteReferenceAddress(StonTokenWriter writer, IStonAddress address) { if (address.InitialContext == null) { throw new StonException("A reference address cannot have a non-existing initial context."); } if (address.RelativePath == null) { throw new StonException("A reference address cannot have a non-existing relative path."); } WriteInitialContext(writer, address.InitialContext); foreach (var segment in address.RelativePath) { WritePathSegment(writer, segment); } }
/// <summary> /// Creates a new reference entity, with a given reference address and optional global identifier. /// </summary> /// <param name="address">The address of the referenced value.</param> /// <param name="globalIdentifier">The global identifier of the entity.</param> /// <returns>The new STON entity.</returns> public IStonReferenceEntity CreateReferenceEntity(IStonAddress address, string globalIdentifier = null) => new StonReferenceEntity(address, globalIdentifier);
/// <summary> /// Creates a structurally equivalent STON address from a given address. /// </summary> /// <param name="address">The address to copy the structure from.</param> public StonAddress(IStonAddress address) : this(address.InitialContext, address.RelativePath) { }
public AReferenceEntity(IStonAddress address, string globalIdentifier = null) { Address = address; GlobalIdentifier = globalIdentifier; }