示例#1
0
        public static object Evaluate([NotNull] this Query query, [NotNull] Opcode opcode, [NotNull] QueryContext contextNode)
        {
            Assert.ArgumentNotNull(query, nameof(query));
            Assert.ArgumentNotNull(opcode, nameof(opcode));
            Assert.ArgumentNotNull(contextNode, nameof(contextNode));

            var item = contextNode.GetQueryContextItem();

            if (item == null)
            {
                return(opcode.Evaluate(query, contextNode));
            }

            var queryTranslator = GetQueryTranslator(contextNode);

            if (queryTranslator == null)
            {
                return(opcode.Evaluate(query, contextNode));
            }

            IDList idList;

            try
            {
                idList = queryTranslator.QueryFast(item.Database, opcode);
            }
            catch
            {
                idList = null;
            }

            if (idList == null)
            {
                return(opcode.Evaluate(query, contextNode));
            }

            if (idList.Count == 1)
            {
                return(new QueryContext(item.Database.DataManager, idList[0]));
            }

            var result = new List <QueryContext>();

            foreach (ID id in idList)
            {
                result.Add(new QueryContext(item.Database.DataManager, id));
            }

            return(result.ToArray());
        }
示例#2
0
        public static string GetString([NotNull] this Query query, [NotNull] QueryContext contextNode, [NotNull] Opcode expression)
        {
            Assert.ArgumentNotNull(query, nameof(query));
            Assert.ArgumentNotNull(contextNode, nameof(contextNode));
            Assert.ArgumentNotNull(expression, nameof(expression));

            return(expression.Evaluate(query, contextNode) as string);
        }
示例#3
0
        public static Item GetItem([NotNull] this Query query, [NotNull] QueryContext contextNode, [NotNull] Opcode expression)
        {
            Assert.ArgumentNotNull(query, nameof(query));
            Assert.ArgumentNotNull(contextNode, nameof(contextNode));
            Assert.ArgumentNotNull(expression, nameof(expression));

            var result = expression.Evaluate(query, contextNode);

            var instance = result as QueryContext;

            if (instance == null)
            {
                return(null);
            }

            return(instance.GetQueryContextItem());
        }