private void Listen() { while (true) { T result = Update(); if (isCancel) { return; } var args = new TArg { Arg = result }; OnMessageReceived?.Invoke(this, args); } }
public TArg GetArguments <TArg>() where TArg : new() { var retVal = new TArg(); var properties = _propertyInfoCacher.GetProperties(typeof(TArg)); var propertyValueProviders = _propertyValueProviderFactory.GetPropertyValueProviders(); foreach (var propertyValueProvider in propertyValueProviders) { foreach (var kvp in properties) { if (propertyValueProvider.HasValue <TArg>(kvp.Key)) { kvp.Value.SetValue(retVal, propertyValueProvider.GetValue <TArg>(kvp.Key, kvp.Value.PropertyType), null); } } } return(retVal); }
static void pushLeftNodes(BoundBinaryOperator binary, ArrayBuilder <BoundBinaryOperator> stack, TArg arg, Action <BoundBinaryOperator, TArg>?binaryOperatorCallback) { Debug.Assert(typeof(TInterpolatedStringType) == typeof(BoundInterpolatedString) || binary.IsUnconvertedInterpolatedStringAddition); BoundBinaryOperator?current = binary; while (current != null) { binaryOperatorCallback?.Invoke(current, arg); stack.Push(current); current = current.Left as BoundBinaryOperator; } }
/// <summary> /// Represents <see cref="Provider{TArg,TServiceType}.Invoke"/> /// </summary> public TService Create(TArg arg) { return(container.Resolve <TService>(new[] { new TypedParameter(typeof(TArg), arg) })); }
static Action CreateTaskCallback(Action <TArg> action, TArg arg) => new(() => action(arg));
static ValueTask <TResult> UnwrapAndTransformAsync(ValueTask <TIntermediate> intermediateResult, Func <TIntermediate, TArg, TResult> transform, TArg arg, CancellationToken cancellationToken) { // Apply the transformation function once a result is available. The behavior depends on the final // status of 'intermediateResult' and the 'cancellationToken'. // // | 'intermediateResult' | 'cancellationToken' | Behavior | // | -------------------------- | ------------------- | ---------------------------------------- | // | Ran to completion | Not cancelled | Apply transform | // | Ran to completion | Cancelled | Cancel result without applying transform | // | Cancelled (matching token) | Cancelled | Cancel result without applying transform | // | Cancelled (mismatch token) | Not cancelled | Cancel result without applying transform | // | Cancelled (mismatch token) | Cancelled | Cancel result without applying transform | // | Direct fault¹ | Not cancelled | Directly fault (exception is not caught) | // | Direct fault¹ | Cancelled | Directly fault (exception is not caught) | // | Indirect fault | Not cancelled | Fault result without applying transform | // | Indirect fault | Cancelled | Cancel result without applying transform | // // ¹ Direct faults are exceptions thrown from 'func' prior to returning a ValueTask<TIntermediate> // instances. Indirect faults are exceptions captured by return an instance of // ValueTask<TIntermediate> which (immediately or eventually) transitions to the faulted state. The // direct fault behavior is currently handled without calling UnwrapAndTransformAsync. return(new ValueTask <TResult>(intermediateResult.AsTask().ContinueWith( task => transform(task.GetAwaiter().GetResult(), arg), cancellationToken, TaskContinuationOptions.LazyCancellation | TaskContinuationOptions.NotOnCanceled | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default))); }