/// <summary>
    /// Creates a <see cref="MethodInfoBasedNodeTypeRegistry"/> and automatically registers all types implementing <see cref="IExpressionNode"/> 
    /// from a given type sequence that offer a public static <c>SupportedMethods</c> field.
    /// </summary>
    /// <returns>A <see cref="MethodInfoBasedNodeTypeRegistry"/> with all <see cref="IExpressionNode"/> types with a <c>SupportedMethods</c>
    /// field registered.</returns>
    public static MethodInfoBasedNodeTypeRegistry CreateFromTypes (IEnumerable<Type> searchedTypes)
    {
      ArgumentUtility.CheckNotNull ("searchedTypes", searchedTypes);

      var expressionNodeTypes = from t in searchedTypes
                                where typeof (IExpressionNode).GetTypeInfo().IsAssignableFrom (t.GetTypeInfo())
                                select t;

      var supportedMethodsForTypes =
          from t in expressionNodeTypes
          let supportedMethodsField = t.GetRuntimeField ("SupportedMethods")
          select new
                 {
                     Type = t,
                     Methods =
                         supportedMethodsField != null && supportedMethodsField.IsStatic
                             ? (IEnumerable<MethodInfo>) supportedMethodsField.GetValue (null)
                             : Enumerable.Empty<MethodInfo>()
                 };

      var registry = new MethodInfoBasedNodeTypeRegistry();

      foreach (var methodsForType in supportedMethodsForTypes)
      {
        registry.Register (methodsForType.Methods, methodsForType.Type);
      }

      return registry;
    }
Example #2
0
        /// <summary>
        /// Creates a <see cref="MethodInfoBasedNodeTypeRegistry"/> and automatically registers all types implementing <see cref="IExpressionNode"/>
        /// from a given type sequence that offer a public static <c>SupportedMethods</c> field.
        /// </summary>
        /// <returns>A <see cref="MethodInfoBasedNodeTypeRegistry"/> with all <see cref="IExpressionNode"/> types with a <c>SupportedMethods</c>
        /// field registered.</returns>
        public static MethodInfoBasedNodeTypeRegistry CreateFromTypes(IEnumerable <Type> searchedTypes)
        {
            ArgumentUtility.CheckNotNull("searchedTypes", searchedTypes);

            var expressionNodeTypes = from t in searchedTypes
                                      where typeof(IExpressionNode).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo())
                                      select t;

            var supportedMethodsForTypes =
                from t in expressionNodeTypes
                let supportedMethodsField = t.GetRuntimeField("SupportedMethods")
                                            select new
            {
                Type    = t,
                Methods =
                    supportedMethodsField != null && supportedMethodsField.IsStatic
                             ? (IEnumerable <MethodInfo>)supportedMethodsField.GetValue(null)
                             : Enumerable.Empty <MethodInfo>()
            };

            var registry = new MethodInfoBasedNodeTypeRegistry();

            foreach (var methodsForType in supportedMethodsForTypes)
            {
                registry.Register(methodsForType.Methods, methodsForType.Type);
            }

            return(registry);
        }
        public static IQueryParser CreateQueryParser()
        {
            //Create Custom node registry
            var customNodeTypeRegistry = new MethodInfoBasedNodeTypeRegistry();

            //Register new clause type
            customNodeTypeRegistry.Register(FilterExpressionNode.SupportedMethods, typeof(FilterExpressionNode));
            customNodeTypeRegistry.Register(LetSelectExpressionNode.SupportedMethods, typeof(LetSelectExpressionNode));
            customNodeTypeRegistry.Register(LetLambdaExpressionNode.SupportedMethods, typeof(LetLambdaExpressionNode));
            customNodeTypeRegistry.Register(TakeExpressionNode.SupportedMethods, typeof(TakeExpressionNode));
            customNodeTypeRegistry.Register(SkipExpressionNode.SupportedMethods, typeof(SkipExpressionNode));
            customNodeTypeRegistry.Register(GroupByExpressionNode.GroupBySupportedMethods, typeof(GroupByExpressionNode));
            customNodeTypeRegistry.Register(LimitExpressionNode.SupportedMethods, typeof(LimitExpressionNode));
            customNodeTypeRegistry.Register(UpdateAndReturnExpressionNode.SupportedMethods, typeof(UpdateAndReturnExpressionNode));
            customNodeTypeRegistry.Register(RemoveAndReturnExpressionNode.SupportedMethods, typeof(RemoveAndReturnExpressionNode));
            customNodeTypeRegistry.Register(InsertAndReturnExpressionNode.SupportedMethods, typeof(InsertAndReturnExpressionNode));
            customNodeTypeRegistry.Register(UpsertAndReturnExpressionNode.SupportedMethods, typeof(UpsertAndReturnExpressionNode));
            customNodeTypeRegistry.Register(InModifyExpressionNode.SupportedMethods, typeof(InModifyExpressionNode));
            customNodeTypeRegistry.Register(ReturnResultModifyExpressionNode.SupportedMethods, typeof(ReturnResultModifyExpressionNode));
            customNodeTypeRegistry.Register(QueryableExtensions.OrderBySupportedMethods, typeof(ArangoDB.Client.Common.Remotion.Linq.Parsing.Structure.IntermediateModel.OrderByExpressionNode));
            customNodeTypeRegistry.Register(QueryableExtensions.OrderByDescendingSupportedMethods, typeof(ArangoDB.Client.Common.Remotion.Linq.Parsing.Structure.IntermediateModel.OrderByDescendingExpressionNode));
            customNodeTypeRegistry.Register(QueryableExtensions.SelectManySupportedMethods, typeof(ArangoDB.Client.Common.Remotion.Linq.Parsing.Structure.IntermediateModel.SelectManyExpressionNode));

            //This creates all the default node types
            var nodeTypeProvider = ExpressionTreeParser.CreateDefaultNodeTypeProvider();

            //add custom node provider to the providers
            //nodeTypeProvider.InnerProviders.Add(customNodeTypeRegistry);

            nodeTypeProvider.InnerProviders.Insert(0, customNodeTypeRegistry);

            var transformerRegistry = ExpressionTransformerRegistry.CreateDefault();
            var processor = ExpressionTreeParser.CreateDefaultProcessor(transformerRegistry);
            var expressionTreeParser = new ExpressionTreeParser(nodeTypeProvider, processor);
            var queryParser = new QueryParser(expressionTreeParser);

            return queryParser;
        }