public Task <IBinding> BindAsync <TValue>(RuntimeBindingContext context, CancellationToken cancellationToken)
        {
            ParameterInfo          parameterInfo          = new FakeParameterInfo(typeof(TValue), _memberInfo, context.Attribute, context.AdditionalAttributes.ToArray());
            BindingProviderContext bindingProviderContext =
                new BindingProviderContext(parameterInfo, bindingDataContract: null, cancellationToken: cancellationToken);

            return(_bindingProvider.TryCreateAsync(bindingProviderContext));
        }
Beispiel #2
0
        public async Task <TValue> BindAsync <TValue>(RuntimeBindingContext context, CancellationToken cancellationToken = default(CancellationToken))
        {
            IBinding binding = await _bindingSource.BindAsync <TValue>(context, cancellationToken);

            if (binding == null)
            {
                throw new InvalidOperationException("No binding found for attribute '" + context.Attribute.GetType() + "'.");
            }

            IValueProvider provider = await binding.BindAsync(new BindingContext(
                                                                  _bindingSource.AmbientBindingContext, cancellationToken));

            if (provider == null)
            {
                return(default(TValue));
            }

            Debug.Assert(provider.Type == typeof(TValue));

            ParameterDescriptor parameterDesciptor = binding.ToParameterDescriptor();

            parameterDesciptor.Name = null; // Remove the dummy name "?" used for runtime binding.

            string value = provider.ToInvokeString();

            IWatchable watchable = provider as IWatchable;

            // Add even if watchable is null to show parameter descriptor in status.
            _watcher.Add(parameterDesciptor, value, watchable);

            IValueBinder binder = provider as IValueBinder;

            if (binder != null)
            {
                _binders.Add(binder);
            }

            IDisposable disposableProvider = provider as IDisposable;

            if (disposableProvider != null)
            {
                _disposable.Add(disposableProvider);
            }

            return((TValue)provider.GetValue());
        }
Beispiel #3
0
        public async Task <TValue> BindAsync <TValue>(Attribute attribute, CancellationToken cancellationToken)
        {
            RuntimeBindingContext context = new RuntimeBindingContext(attribute);

            return(await BindAsync <TValue>(context, cancellationToken));
        }