JsonReferenceExtensions
Extensions to work with IJsonReference.
namespace NJsonSchema.References
{
public static class JsonReferenceExtensions
{
public static object FindParentDocument(this IJsonReference obj)
{
if (obj.DocumentPath != null)
return obj;
object possibleRoot = obj.PossibleRoot;
if (possibleRoot == null)
return obj;
while ((possibleRoot as IJsonReference)?.PossibleRoot != null) {
possibleRoot = ((IJsonReference)possibleRoot).PossibleRoot;
IDocumentPathProvider documentPathProvider;
if ((documentPathProvider = (possibleRoot as IDocumentPathProvider)) != null && documentPathProvider.DocumentPath != null)
return possibleRoot;
}
return possibleRoot;
}
}
}