/// <summary> /// Creates a new STON address, with a given initial context and path segments. /// </summary> /// <param name="initialContext">The initial context to start from.</param> /// <param name="relativePath">The path segments leading to the destination.</param> public StonAddress(IStonInitialContext initialContext, IEnumerable <IStonPathSegment> relativePath = null) { if (initialContext == null) { throw new ArgumentNullException("initialContext"); } InitialContext = StonInitialContext.Copy(initialContext); RelativePath = relativePath?.Select(segment => StonPathSegment.Copy(segment)).ToList() ?? Enumerable.Empty <IStonPathSegment>(); }
// checks that a given initial context has a correct canonical form private void ExpectValidContext(IStonInitialContext context, string canonicalForm) { try { Assert.AreEqual(canonicalForm, new StonReferenceEntity(new StonAddress(context, null)).ToCanonicalForm()); } catch (StonException ex) { Assert.Fail(ex.Message); } }
// checks that a given initial context is invalid // and causes an error with a specific message private void ExpectInvalidContext(IStonInitialContext context, string message) { try { new StonReferenceEntity(new StonAddress(context, null)); Assert.Fail("The reference is valid. This should *not* have happened."); } catch (StonException ex) { Assert.AreEqual(message, ex.Message); } }
// reads a STON reference entity address private IStonAddress ReadAddress(StonTokenReader reader) { IStonInitialContext initialContext = ReadInitialContext(reader); var path = new List <IStonPathSegment>(); while (reader.Peek().HasChartype(StonChartype.PathSegmentBegin)) { path.Add(ReadPathSegment(reader)); } return(ElementFactory.CreateAddress(initialContext, path)); }
// writes any initial context private void WriteInitialContext(StonTokenWriter writer, IStonInitialContext context) { if (context is IStonAncestorInitialContext) { WriteInitialContext(writer, context as IStonAncestorInitialContext); } else if (context is IStonGlobalEntityInitialContext) { WriteInitialContext(writer, context as IStonGlobalEntityInitialContext); } else { throw new StonImplementationException(context.GetType(), typeof(IStonInitialContext), typeof(IStonAncestorInitialContext), typeof(IStonGlobalEntityInitialContext)); } }
/// <summary> /// Creates a structurally equivalent initial context from a given context. /// </summary> /// <param name="context">The context to copy the structure of.</param> /// <returns>A structurally equivalent copy of the given context.</returns> public static IStonInitialContext Copy(IStonInitialContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (context is IStonAncestorInitialContext) { return(StonAncestorInitialContext.Copy(context as IStonAncestorInitialContext)); } if (context is IStonGlobalEntityInitialContext) { return(StonGlobalEntityInitialContext.Copy(context as IStonGlobalEntityInitialContext)); } throw new StonImplementationException(context.GetType(), typeof(IStonInitialContext), typeof(IStonAncestorInitialContext), typeof(IStonGlobalEntityInitialContext)); }
/// <summary> /// Checks the validity of a given STON initial context. /// </summary> /// <param name="initialContext">The initial context to check the validity of.</param> public static void ValidateInitialContext(IStonInitialContext initialContext) { if (initialContext == null) { throw new ArgumentNullException("initialContext"); } else if (initialContext is IStonAncestorInitialContext) { ValidateInitialContext(initialContext as IStonAncestorInitialContext); } else if (initialContext is IStonGlobalEntityInitialContext) { ValidateInitialContext(initialContext as IStonGlobalEntityInitialContext); } else { throw new StonImplementationException(initialContext.GetType(), typeof(IStonInitialContext), typeof(IStonAncestorInitialContext), typeof(IStonGlobalEntityInitialContext)); } }
/// <summary> /// Creates a new STON address, with a given initial context and path segments. /// </summary> /// <param name="initialContext">The initial context to start from.</param> /// <param name="relativePath">The path segments leading to the destination.</param> /// <returns>The new STON reference address.</returns> public IStonAddress CreateAddress(IStonInitialContext initialContext, IEnumerable <IStonPathSegment> relativePath) => new StonAddress(initialContext, relativePath);
/// <summary> /// Creates a new STON address, with a given initial context and path segments. /// </summary> /// <param name="initialContext">The initial context to start of.</param> /// <param name="relativePath">The path segments leading to the destination.</param> public StonAddress(IStonInitialContext initialContext, params IStonPathSegment[] relativePath) : this(initialContext, relativePath as IEnumerable <IStonPathSegment>) { }
public AnAddress(IStonInitialContext initialContext, IEnumerable <IStonPathSegment> relativePath) { InitialContext = initialContext; RelativePath = relativePath; }