DistinctExpressionNode

Namespace: Remotion.Linq
We found 10 examples in language CSharp for this search. You will see 37 fragments of code.

    public override void SetUp ()
    {
      base.SetUp ();
      _node = new DistinctExpressionNode (CreateParseInfo ());
    }

    [Test]
    public void GetSupportedMethods ()
    {
      Assert.That (
          DistinctExpressionNode.GetSupportedMethods(),
          Is.EquivalentTo (
              new[]
              {
                  GetGenericMethodDefinition (() => Queryable.Distinct<object> (null)),
                  GetGenericMethodDefinition (() => Enumerable.Distinct<object> (null))
              }));
    }


    public override Expression Resolve (
        ParameterExpression inputParameter, Expression expressionToBeResolved, ClauseGenerationContext clauseGenerationContext)
    {
      ArgumentUtility.CheckNotNull ("inputParameter", inputParameter);
      ArgumentUtility.CheckNotNull ("expressionToBeResolved", expressionToBeResolved);

      // this simply streams its input data to the output without modifying its structure, so we resolve by passing on the data to the previous node
      return Source.Resolve (inputParameter, expressionToBeResolved, clauseGenerationContext);
    }

    protected override ResultOperatorBase CreateResultOperator (ClauseGenerationContext clauseGenerationContext)
    {
      return new DistinctResultOperator();
    }


      public bool AmbiguousMethod (T1 p)
      {
        return false;
      }

      public bool AmbiguousMethod (T2 p)
      {
        return false;
      }

    public override void SetUp ()
    {
      base.SetUp ();
      _clauseToAddInApply = new WhereClause (Expression.Constant (false));
      _node = new TestMethodCallExpressionNode (CreateParseInfo (SourceNode, "test"), _clauseToAddInApply);
      
      var distinctMethod = ReflectionUtility.GetMethod (() => new int[0].Distinct ());
      _resultOperatorSource = new DistinctExpressionNode (CreateParseInfo (SourceNode, "distinct", distinctMethod));
      var method = ReflectionUtility.GetMethod (() => Queryable.Take<int> (null, 0));
      _nodeWithResultOperatorSource = new TestMethodCallExpressionNode (CreateParseInfo (_resultOperatorSource, "test", method), _clauseToAddInApply);
      _queryModelWithResultOperator = QueryModel.Clone ();
      _queryModelWithResultOperator.ResultOperators.Add (new DistinctResultOperator ());
    }

    [Test]
    public void Apply_LeavesQueryModel_WithoutResultOperator ()
    {
      var newQueryModel = _node.Apply (QueryModel, ClauseGenerationContext);
      Assert.That (newQueryModel, Is.SameAs (QueryModel));
    }

    [Test]
    public void Apply_CallsSpecificApply ()
    {
      var newQueryModel = _node.Apply (QueryModel, ClauseGenerationContext);
      Assert.That (newQueryModel, Is.SameAs (QueryModel));
      Assert.That (newQueryModel.BodyClauses[0], Is.SameAs (_clauseToAddInApply));
    }

    [Test]
    public void Apply_WrapsQueryModel_AfterResultOperator ()
    {
      var newQueryModel = _nodeWithResultOperatorSource.Apply (_queryModelWithResultOperator, ClauseGenerationContext);

      Assert.That (newQueryModel, Is.Not.SameAs (_queryModelWithResultOperator));
      Assert.That (newQueryModel.MainFromClause.ItemType, Is.SameAs (typeof (int))); // because SourceNode is of type int[]
      Assert.That (newQueryModel.MainFromClause.ItemName, Is.EqualTo ("distinct"));
      Assert.That (newQueryModel.MainFromClause.FromExpression, Is.InstanceOf (typeof (SubQueryExpression)));
      Assert.That (((SubQueryExpression) newQueryModel.MainFromClause.FromExpression).QueryModel, Is.SameAs (_queryModelWithResultOperator));

      var newSelectClause = newQueryModel.SelectClause;
      Assert.That (((QuerySourceReferenceExpression) newSelectClause.Selector).ReferencedQuerySource, Is.SameAs (newQueryModel.MainFromClause));
    }


    protected abstract ResultOperatorBase CreateResultOperator (ClauseGenerationContext clauseGenerationContext);

    protected override QueryModel ApplyNodeSpecificSemantics (QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
    {
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);

      var resultOperator = CreateResultOperator (clauseGenerationContext);
      queryModel.ResultOperators.Add (resultOperator);
      return queryModel;
    }

    protected override QueryModel WrapQueryModelAfterEndOfQuery (QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
    {
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);

      // Result operators can safely be appended to the previous query model even after another result operator, so do not wrap the previous
      // query model.
      return queryModel;
    }


		protected abstract ResultOperatorBase CreateResultOperator(ClauseGenerationContext clauseGenerationContext);

		protected override QueryModel ApplyNodeSpecificSemantics(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
		{
			var resultOperator = CreateResultOperator(clauseGenerationContext);
			queryModel.ResultOperators.Add(resultOperator);
			return queryModel;
		}

		protected override QueryModel WrapQueryModelAfterEndOfQuery(QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
		{
			// Result operators can safely be appended to the previous query model even after another result operator, so do not wrap the previous
			// query model.
			return queryModel;
		}


    public static MethodInfoBasedNodeTypeRegistry CreateFromRelinqAssembly()
    {
      MethodInfoBasedNodeTypeRegistry nodeTypeRegistry = new MethodInfoBasedNodeTypeRegistry();
      nodeTypeRegistry.Register(AggregateExpressionNode.GetSupportedMethods(), typeof (AggregateExpressionNode));
      nodeTypeRegistry.Register(AggregateFromSeedExpressionNode.GetSupportedMethods(), typeof (AggregateFromSeedExpressionNode));
      nodeTypeRegistry.Register(AllExpressionNode.GetSupportedMethods(), typeof (AllExpressionNode));
      nodeTypeRegistry.Register(AnyExpressionNode.GetSupportedMethods(), typeof (AnyExpressionNode));
      nodeTypeRegistry.Register(AverageExpressionNode.GetSupportedMethods(), typeof (AverageExpressionNode));
      nodeTypeRegistry.Register(CastExpressionNode.GetSupportedMethods(), typeof (CastExpressionNode));
      nodeTypeRegistry.Register(ConcatExpressionNode.GetSupportedMethods(), typeof (ConcatExpressionNode));
      nodeTypeRegistry.Register(ContainsExpressionNode.GetSupportedMethods(), typeof (ContainsExpressionNode));
      nodeTypeRegistry.Register(CountExpressionNode.GetSupportedMethods(), typeof (CountExpressionNode));
      nodeTypeRegistry.Register(DefaultIfEmptyExpressionNode.GetSupportedMethods(), typeof (DefaultIfEmptyExpressionNode));
      nodeTypeRegistry.Register(DistinctExpressionNode.GetSupportedMethods(), typeof (DistinctExpressionNode));
      nodeTypeRegistry.Register(ExceptExpressionNode.GetSupportedMethods(), typeof (ExceptExpressionNode));
      nodeTypeRegistry.Register(FirstExpressionNode.GetSupportedMethods(), typeof (FirstExpressionNode));
      nodeTypeRegistry.Register(GroupByExpressionNode.GetSupportedMethods(), typeof (GroupByExpressionNode));
      nodeTypeRegistry.Register(GroupByWithResultSelectorExpressionNode.GetSupportedMethods(), typeof (GroupByWithResultSelectorExpressionNode));
      nodeTypeRegistry.Register(GroupJoinExpressionNode.GetSupportedMethods(), typeof (GroupJoinExpressionNode));
      nodeTypeRegistry.Register(IntersectExpressionNode.GetSupportedMethods(), typeof (IntersectExpressionNode));
      nodeTypeRegistry.Register(JoinExpressionNode.GetSupportedMethods(), typeof (JoinExpressionNode));
      nodeTypeRegistry.Register(LastExpressionNode.GetSupportedMethods(), typeof (LastExpressionNode));
      nodeTypeRegistry.Register(LongCountExpressionNode.GetSupportedMethods(), typeof (LongCountExpressionNode));
      nodeTypeRegistry.Register(MaxExpressionNode.GetSupportedMethods(), typeof (MaxExpressionNode));
      nodeTypeRegistry.Register(MinExpressionNode.GetSupportedMethods(), typeof (MinExpressionNode));
      nodeTypeRegistry.Register(OfTypeExpressionNode.GetSupportedMethods(), typeof (OfTypeExpressionNode));
      nodeTypeRegistry.Register(OrderByDescendingExpressionNode.GetSupportedMethods(), typeof (OrderByDescendingExpressionNode));
      nodeTypeRegistry.Register(OrderByExpressionNode.GetSupportedMethods(), typeof (OrderByExpressionNode));
      nodeTypeRegistry.Register(ReverseExpressionNode.GetSupportedMethods(), typeof (ReverseExpressionNode));
      nodeTypeRegistry.Register(SelectExpressionNode.GetSupportedMethods(), typeof (SelectExpressionNode));
      nodeTypeRegistry.Register(SelectManyExpressionNode.GetSupportedMethods(), typeof (SelectManyExpressionNode));
      nodeTypeRegistry.Register(SingleExpressionNode.GetSupportedMethods(), typeof (SingleExpressionNode));
      nodeTypeRegistry.Register(SkipExpressionNode.GetSupportedMethods(), typeof (SkipExpressionNode));
      nodeTypeRegistry.Register(SumExpressionNode.GetSupportedMethods(), typeof (SumExpressionNode));
      nodeTypeRegistry.Register(TakeExpressionNode.GetSupportedMethods(), typeof (TakeExpressionNode));
      nodeTypeRegistry.Register(ThenByDescendingExpressionNode.GetSupportedMethods(), typeof (ThenByDescendingExpressionNode));
      nodeTypeRegistry.Register(ThenByExpressionNode.GetSupportedMethods(), typeof (ThenByExpressionNode));
      nodeTypeRegistry.Register(UnionExpressionNode.GetSupportedMethods(), typeof (UnionExpressionNode));
      nodeTypeRegistry.Register(WhereExpressionNode.GetSupportedMethods(), typeof (WhereExpressionNode));
      return nodeTypeRegistry;
    }

    public static MethodInfo GetRegisterableMethodDefinition(
      MethodInfo method,
      bool throwOnAmbiguousMatch)
    {
      ArgumentUtility.CheckNotNull<MethodInfo>(nameof (method), method);
      MethodInfo genericMethodDefinition = method.IsGenericMethod ? method.GetGenericMethodDefinition() : method;
      if (!genericMethodDefinition.DeclaringType.GetTypeInfo().IsGenericType)
        return genericMethodDefinition;
      Lazy<MethodInfo[]> lazy;
      lock (MethodInfoBasedNodeTypeRegistry.s_genericMethodDefinitionCandidates)
      {
        if (!MethodInfoBasedNodeTypeRegistry.s_genericMethodDefinitionCandidates.TryGetValue(method, out lazy))
        {
          lazy = new Lazy<MethodInfo[]>((Func<MethodInfo[]>) (() => MethodInfoBasedNodeTypeRegistry.GetGenericMethodDefinitionCandidates(genericMethodDefinition)));
          MethodInfoBasedNodeTypeRegistry.s_genericMethodDefinitionCandidates.Add(method, lazy);
        }
      }
      if (lazy.Value.Length == 1)
        return ((IEnumerable<MethodInfo>) lazy.Value).Single<MethodInfo>();
      if (!throwOnAmbiguousMatch)
        return (MethodInfo) null;
      throw new NotSupportedException(string.Format("A generic method definition cannot be resolved for method '{0}' on type '{1}' because a distinct match is not possible. The method can still be registered using the following syntax:\r\n\r\npublic static readonly NameBasedRegistrationInfo[] SupportedMethodNames = \r\n    new[] {{\r\n        new NameBasedRegistrationInfo (\r\n            \"{2}\", \r\n            mi => /* match rule based on MethodInfo */\r\n        )\r\n    }};", (object) method, (object) genericMethodDefinition.DeclaringType.GetGenericTypeDefinition(), (object) method.Name));
    }

    private static MethodInfo[] GetGenericMethodDefinitionCandidates(
      MethodInfo referenceMethodDefinition)
    {
      Type genericTypeDefinition = referenceMethodDefinition.DeclaringType.GetGenericTypeDefinition();
      \u003C\u003Ef__AnonymousType0<string, Type>[] referenceMethodSignature = new \u003C\u003Ef__AnonymousType0<string, Type>[1]
      {
        new
        {
          Name = "returnValue",
          Type = referenceMethodDefinition.ReturnType
        }
      }.Concat(((IEnumerable<ParameterInfo>) referenceMethodDefinition.GetParameters()).Select(p => new
      {
        Name = p.Name,
        Type = p.ParameterType
      })).ToArray();
      \u003C\u003Ef__AnonymousType1<MethodInfo, string[], Type[]>[] array = genericTypeDefinition.GetRuntimeMethods().Select(m => new
      {
        Method = m,
        SignatureNames = ((IEnumerable<string>) new string[1]
        {
          "returnValue"
        }).Concat<string>(((IEnumerable<ParameterInfo>) m.GetParameters()).Select<ParameterInfo, string>((Func<ParameterInfo, string>) (p => p.Name))).ToArray<string>(),
        SignatureTypes = ((IEnumerable<Type>) new Type[1]
        {
          m.ReturnType
        }).Concat<Type>(((IEnumerable<ParameterInfo>) m.GetParameters()).Select<ParameterInfo, Type>((Func<ParameterInfo, Type>) (p => p.ParameterType))).ToArray<Type>()
      }).Where(c => c.Method.Name == referenceMethodDefinition.Name && c.SignatureTypes.Length == referenceMethodSignature.Length).ToArray();
      for (int i = 0; i < referenceMethodSignature.Length; ++i)
        array = array.Where(c => c.SignatureNames[i] == referenceMethodSignature[i].Name).Where(c => c.SignatureTypes[i] == referenceMethodSignature[i].Type || c.SignatureTypes[i].GetTypeInfo().ContainsGenericParameters).ToArray();
      return array.Select(c => c.Method).ToArray<MethodInfo>();
    }

    public void Register(IEnumerable<MethodInfo> methods, Type nodeType)
    {
      ArgumentUtility.CheckNotNull<IEnumerable<MethodInfo>>(nameof (methods), methods);
      ArgumentUtility.CheckNotNull<Type>(nameof (nodeType), nodeType);
      ArgumentUtility.CheckTypeIsAssignableFrom(nameof (nodeType), nodeType, typeof (IExpressionNode));
      foreach (MethodInfo method in methods)
      {
        if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
          throw new InvalidOperationException(string.Format("Cannot register closed generic method '{0}', try to register its generic method definition instead.", (object) method.Name));
        if (method.DeclaringType.GetTypeInfo().IsGenericType && !method.DeclaringType.GetTypeInfo().IsGenericTypeDefinition)
          throw new InvalidOperationException(string.Format("Cannot register method '{0}' in closed generic type '{1}', try to register its equivalent in the generic type definition instead.", (object) method.Name, (object) method.DeclaringType));
        this._registeredMethodInfoTypes[method] = nodeType;
      }
    }

    public bool IsRegistered(MethodInfo method)
    {
      ArgumentUtility.CheckNotNull<MethodInfo>(nameof (method), method);
      return this.GetNodeType(method) != (Type) null;
    }

    public Type GetNodeType(MethodInfo method)
    {
      ArgumentUtility.CheckNotNull<MethodInfo>(nameof (method), method);
      MethodInfo methodDefinition = MethodInfoBasedNodeTypeRegistry.GetRegisterableMethodDefinition(method, false);
      if (methodDefinition == (MethodInfo) null)
        return (Type) null;
      Type type;
      this._registeredMethodInfoTypes.TryGetValue(methodDefinition, out type);
      return type;
    }


    protected abstract ResultOperatorBase CreateResultOperator (ClauseGenerationContext clauseGenerationContext);

    protected override QueryModel ApplyNodeSpecificSemantics (QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
    {
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);

      var resultOperator = CreateResultOperator (clauseGenerationContext);
      queryModel.ResultOperators.Add (resultOperator);
      return queryModel;
    }

    protected override QueryModel WrapQueryModelAfterEndOfQuery (QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
    {
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);

      // Result operators can safely be appended to the previous query model even after another result operator, so do not wrap the previous
      // query model.
      return queryModel;
    }


        protected abstract ResultOperatorBase CreateResultOperator(ClauseGenerationContext clauseGenerationContext);

        protected override void ApplyNodeSpecificSemantics(QueryModel queryModel,
            ClauseGenerationContext clauseGenerationContext)
        {
            //NOTE: Do not seal ApplyNodeSpecificSemantics() in ResultOperatorExpressionNodeBase. It is overridden by e.g. Fetch-operators.
            ArgumentUtility.CheckNotNull("queryModel", queryModel);

            var resultOperator = CreateResultOperator(clauseGenerationContext);
            queryModel.ResultOperators.Add(resultOperator);
        }

        protected sealed override QueryModel WrapQueryModelAfterEndOfQuery(QueryModel queryModel,
            ClauseGenerationContext clauseGenerationContext)
        {
            ArgumentUtility.CheckNotNull("queryModel", queryModel);

            // Result operators can safely be appended to the previous query model even after another result operator, so do not wrap the previous
            // query model.
            return queryModel;
        }

        private static MethodCallExpressionParseInfo TransformParseInfo(
            MethodCallExpressionParseInfo parseInfo,
            LambdaExpression optionalPredicate,
            LambdaExpression optionalSelector)
        {
            var source = parseInfo.Source;

            if (optionalPredicate != null)
                source = new WhereExpressionNode(parseInfo, optionalPredicate);

            if (optionalSelector != null)
            {
                var newParseInfo = new MethodCallExpressionParseInfo(parseInfo.AssociatedIdentifier, source,
                    parseInfo.ParsedExpression);
                source = new SelectExpressionNode(newParseInfo, optionalSelector);
            }

            return new MethodCallExpressionParseInfo(parseInfo.AssociatedIdentifier, source,
                parseInfo.ParsedExpression);
        }


    protected abstract ResultOperatorBase CreateResultOperator (ClauseGenerationContext clauseGenerationContext);

    protected override void ApplyNodeSpecificSemantics (QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
    {
      //NOTE: Do not seal ApplyNodeSpecificSemantics() in ResultOperatorExpressionNodeBase. It is overridden by e.g. Fetch-operators.
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);

      var resultOperator = CreateResultOperator (clauseGenerationContext);
      queryModel.ResultOperators.Add (resultOperator);
    }

    protected sealed override QueryModel WrapQueryModelAfterEndOfQuery (QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
    {
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);

      // Result operators can safely be appended to the previous query model even after another result operator, so do not wrap the previous
      // query model.
      return queryModel;
    }

    private static MethodCallExpressionParseInfo TransformParseInfo (
        MethodCallExpressionParseInfo parseInfo,
        LambdaExpression optionalPredicate,
        LambdaExpression optionalSelector)
    {
      var source = parseInfo.Source;

      if (optionalPredicate != null)
        source = new WhereExpressionNode (parseInfo, optionalPredicate);

      if (optionalSelector != null)
      {
        var newParseInfo = new MethodCallExpressionParseInfo (parseInfo.AssociatedIdentifier, source, parseInfo.ParsedExpression);
        source = new SelectExpressionNode (newParseInfo, optionalSelector);
      }

      return new MethodCallExpressionParseInfo (parseInfo.AssociatedIdentifier, source, parseInfo.ParsedExpression);
    }


    protected abstract ResultOperatorBase CreateResultOperator (ClauseGenerationContext clauseGenerationContext);

    protected override void ApplyNodeSpecificSemantics (QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
    {
      //NOTE: Do not seal ApplyNodeSpecificSemantics() in ResultOperatorExpressionNodeBase. It is overridden by e.g. Fetch-operators.
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);

      var resultOperator = CreateResultOperator (clauseGenerationContext);
      queryModel.ResultOperators.Add (resultOperator);
    }

    protected sealed override QueryModel WrapQueryModelAfterEndOfQuery (QueryModel queryModel, ClauseGenerationContext clauseGenerationContext)
    {
      ArgumentUtility.CheckNotNull ("queryModel", queryModel);

      // Result operators can safely be appended to the previous query model even after another result operator, so do not wrap the previous
      // query model.
      return queryModel;
    }

    private static MethodCallExpressionParseInfo TransformParseInfo (
        MethodCallExpressionParseInfo parseInfo,
        LambdaExpression optionalPredicate,
        LambdaExpression optionalSelector)
    {
      var source = parseInfo.Source;

      if (optionalPredicate != null)
        source = new WhereExpressionNode (parseInfo, optionalPredicate);

      if (optionalSelector != null)
      {
        var newParseInfo = new MethodCallExpressionParseInfo (parseInfo.AssociatedIdentifier, source, parseInfo.ParsedExpression);
        source = new SelectExpressionNode (newParseInfo, optionalSelector);
      }

      return new MethodCallExpressionParseInfo (parseInfo.AssociatedIdentifier, source, parseInfo.ParsedExpression);
    }

Remotion.Linq.Parsing.Structure.IntermediateModel.DistinctExpressionNode : IExpressionNode

Constructors :

public DistinctExpressionNode(MethodCallExpressionParseInfo parseInfo = )

Methods :

public static IEnumerable<MethodInfo> GetSupportedMethods()
public Expression Resolve(ParameterExpression inputParameter = , Expression expressionToBeResolved = , ClauseGenerationContext clauseGenerationContext = )
public MethodCallExpression get_ParsedExpression()
public String get_AssociatedIdentifier()
public IExpressionNode get_Source()
public Type get_NodeResultType()
public QueryModel Apply(QueryModel queryModel = , ClauseGenerationContext clauseGenerationContext = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()

Other methods