AsyncJsonReferenceVisitorBase
Visitor to transform an object with JsonSchema objects.
using Newtonsoft.Json.Serialization;
using NJsonSchema.References;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace NJsonSchema.Visitors
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public abstract class AsyncJsonReferenceVisitorBase
{
private readonly IContractResolver _contractResolver;
protected AsyncJsonReferenceVisitorBase()
: this(new DefaultContractResolver())
{
}
protected AsyncJsonReferenceVisitorBase(IContractResolver contractResolver)
{
_contractResolver = contractResolver;
}
[AsyncStateMachine(typeof(<VisitAsync>d__3))]
public virtual Task VisitAsync(object obj, CancellationToken cancellationToken)
{
<VisitAsync>d__3 stateMachine = default(<VisitAsync>d__3);
stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create();
stateMachine.<>4__this = this;
stateMachine.obj = obj;
stateMachine.cancellationToken = cancellationToken;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
protected abstract Task<IJsonReference> VisitJsonReferenceAsync(IJsonReference reference, string path, [System.Runtime.CompilerServices.Nullable(2)] string typeNameHint, CancellationToken cancellationToken);
[AsyncStateMachine(typeof(<VisitAsync>d__5))]
protected virtual Task VisitAsync(object obj, string path, [System.Runtime.CompilerServices.Nullable(2)] string typeNameHint, ISet<object> checkedObjects, Action<object> replacer, CancellationToken cancellationToken)
{
<VisitAsync>d__5 stateMachine = default(<VisitAsync>d__5);
stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create();
stateMachine.<>4__this = this;
stateMachine.obj = obj;
stateMachine.path = path;
stateMachine.typeNameHint = typeNameHint;
stateMachine.checkedObjects = checkedObjects;
stateMachine.replacer = replacer;
stateMachine.cancellationToken = cancellationToken;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
private static void ReplaceOrDelete<[System.Runtime.CompilerServices.Nullable(2)] T>(ObservableCollection<T> collection, int index, T obj)
{
((Collection<T>)collection).RemoveAt(index);
if (obj != null)
((Collection<T>)collection).Insert(index, obj);
}
private static void ReplaceOrDelete(IList collection, int index, object obj)
{
collection.RemoveAt(index);
if (obj != null)
collection.Insert(index, obj);
}
}
}