Exemple #1
0
        public bool TryGetValue(TKey key, [NotNullWhen(true)] out TValue?value)
        {
            if (_localDictionary.TryGetValue(key, out var localEntry) && localEntry.TryGetValue(out value))
            {
                return(true);
            }

            if (_globalDictionary.TryGetValue(key, out var globalEntry) && globalEntry.TryGetValue(out value) && globalEntry.AddReference())
            {
                if (localEntry is not null)
                {
                    var valueTask = localEntry.RemoveReference();
                    Infra.Assert(valueTask.IsCompleted);
                    valueTask.GetAwaiter().GetResult();
                }

                _localDictionary[key] = globalEntry;

                return(true);
            }

            value = default;

            return(false);
        }
Exemple #2
0
            public ValueTask <IDataModelHandler> CreateHandler(IFactoryContext factoryContext,
                                                               string dataModelType,
                                                               IErrorProcessor?errorProcessor,
                                                               CancellationToken token)
            {
                Infra.Assert(CanHandle(dataModelType));

                return(new ValueTask <IDataModelHandler>(new EcmaScriptDataModelHandler(errorProcessor)));
            }
Exemple #3
0
            public ValueTask <DataModelValue> Evaluate(IExecutionContext executionContext, CancellationToken token)
            {
                if (executionContext is null)
                {
                    throw new ArgumentNullException(nameof(executionContext));
                }

                Infra.Assert(!_dispatcher._valueEvaluators.IsDefault);

                var valueEvaluator = _dispatcher._valueEvaluators[_index];

                return(Evaluate(valueEvaluator, executionContext, token));
            }
Exemple #4
0
            public ValueTask Assign(IExecutionContext executionContext, DataModelValue value, CancellationToken token)
            {
                if (executionContext is null)
                {
                    throw new ArgumentNullException(nameof(executionContext));
                }

                Infra.Assert(!_dispatcher._locationEvaluators.IsDefault);

                var locationEvaluator = _dispatcher._locationEvaluators[_index];

                return(locationEvaluator.SetValue(value, executionContext, token));
            }
Exemple #5
0
        private static XPathNodeIterator CreateIterator(DataModelList list, string key)
        {
            var navigator = new DataModelXPathNavigator(list);

            navigator.MoveToFirstChild();
            while (navigator.Name != key)
            {
                var moved = navigator.MoveToNext();

                Infra.Assert(moved);
            }

            return(new XPathSingleElementIterator(navigator));
        }