Beispiel #1
0
 /// <summary>
 /// Creates a structurally equivalent path segment from a given segment.
 /// </summary>
 /// <param name="segment">The segment to copy the structure of.</param>
 /// <returns>A structurally equivalent copy of the given segment.</returns>
 public static IStonPathSegment Copy(IStonPathSegment segment)
 {
     if (segment == null)
     {
         throw new ArgumentNullException("segment");
     }
     if (segment is IStonAncestorPathSegment)
     {
         return(StonAncestorPathSegment.Copy(segment as IStonAncestorPathSegment));
     }
     if (segment is IStonMemberPathSegment)
     {
         return(StonMemberPathSegment.Copy(segment as IStonMemberPathSegment));
     }
     if (segment is IStonCollectionElementPathSegment)
     {
         return(StonCollectionElementPathSegment.Copy(segment as IStonCollectionElementPathSegment));
     }
     throw new StonImplementationException(segment.GetType(), typeof(IStonPathSegment), typeof(IStonAncestorPathSegment), typeof(IStonMemberPathSegment), typeof(IStonCollectionElementPathSegment));
 }
Beispiel #2
0
 /// <summary>
 /// Checks the validity of a given STON path segment.
 /// </summary>
 /// <param name="segment">The path segment to check the validity of.</param>
 public static void ValidatePathSegment(IStonPathSegment segment)
 {
     if (segment == null)
     {
         throw new ArgumentNullException("segment");
     }
     else if (segment is IStonAncestorPathSegment)
     {
         ValidatePathSegment(segment as IStonAncestorPathSegment);
     }
     else if (segment is IStonMemberPathSegment)
     {
         ValidatePathSegment(segment as IStonMemberPathSegment);
     }
     else if (segment is IStonCollectionElementPathSegment)
     {
         ValidatePathSegment(segment as IStonCollectionElementPathSegment);
     }
     else
     {
         throw new StonImplementationException(segment.GetType(), typeof(IStonPathSegment), typeof(IStonAncestorPathSegment), typeof(IStonMemberPathSegment), typeof(IStonCollectionElementPathSegment));
     }
 }
Beispiel #3
0
 // writes any path segment
 private void WritePathSegment(StonTokenWriter writer, IStonPathSegment segment)
 {
     if (segment == null)
     {
         throw new StonException("A non-existing path segment has been found in the structure to be written.");
     }
     else if (segment is IStonAncestorPathSegment)
     {
         WritePathSegment(writer, segment as IStonAncestorPathSegment);
     }
     else if (segment is IStonMemberPathSegment)
     {
         WritePathSegment(writer, segment as IStonMemberPathSegment);
     }
     else if (segment is IStonCollectionElementPathSegment)
     {
         WritePathSegment(writer, segment as IStonCollectionElementPathSegment);
     }
     else
     {
         throw new StonImplementationException(segment.GetType(), typeof(IStonPathSegment), typeof(IStonAncestorPathSegment), typeof(IStonMemberPathSegment), typeof(IStonCollectionElementPathSegment));
     }
 }