Skip to content

Commit

Permalink
Added more helpers to handle result data objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Feb 23, 2024
1 parent 0ef04a7 commit facb98c
Showing 1 changed file with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public static class MiddlewareContextMarshal
/// <param name="context">
/// The resolver context.
/// </param>
/// <returns></returns>
/// <returns>
/// Returns the result data of the current resolver context.
/// </returns>
public static ObjectResult? GetParentResultUnsafe(IResolverContext context)
{
if (context is null)
Expand All @@ -30,4 +32,54 @@ public static class MiddlewareContextMarshal
? middlewareContext.ParentResult
: null;
}

/// <summary>
/// Gets the parent result data of the current <paramref name="resultData"/>.
/// </summary>
/// <param name="resultData">
/// The result data for which to get the parent.
/// </param>
/// <typeparam name="T">
/// The type of the result data.
/// </typeparam>
/// <returns>
/// Returns the parent result data of the current <paramref name="resultData"/>.
/// </returns>
/// <exception cref="ArgumentNullException">
/// Throws if <paramref name="resultData"/> is <c>null</c>.
/// </exception>
public static ResultData? GetParent<T>(T resultData) where T : ResultData
{
if (resultData == null)
{
throw new ArgumentNullException(nameof(resultData));
}

return resultData.Parent;
}

/// <summary>
/// Gets the index under which the <paramref name="resultData"/> is stored in the parent result.
/// </summary>
/// <param name="resultData">
/// The result data for which to get the parent index.
/// </param>
/// <typeparam name="T">
/// The type of the result data.
/// </typeparam>
/// <returns>
/// Returns the index under which the <paramref name="resultData"/> is stored in the parent result.
/// </returns>
/// <exception cref="ArgumentNullException">
/// Throws if <paramref name="resultData"/> is <c>null</c>.
/// </exception>
public static int GetParentIndex<T>(T resultData) where T : ResultData
{
if (resultData == null)
{
throw new ArgumentNullException(nameof(resultData));
}

return resultData.ParentIndex;
}
}

0 comments on commit facb98c

Please sign in to comment.