Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BinaryExpression.AndAlso with user defined method #28992

Closed
dmitry-lipetsk opened this issue Mar 16, 2019 · 4 comments
Closed

BinaryExpression.AndAlso with user defined method #28992

dmitry-lipetsk opened this issue Mar 16, 2019 · 4 comments

Comments

@dmitry-lipetsk
Copy link

Hello,

I want to create 'AndAlso' expression object, which will use my implementation of operation method:

class Op2_Code__AndAlso___Boolean__Boolean
{
 private static Boolean Exec_V_V(Boolean a,Boolean b)
 {
  return a && b;
 }//Exec_V_V
};//class Op2_Code__AndAlso___Boolean__Boolean

And got the exception from:

>System.Linq.Expressions.dll!System.Linq.Expressions.Expression.ValidateUserDefinedConditionalLogicOperator(System.Linq.Expressions.ExpressionType nodeType, System.Type left, System.Type right, System.Reflection.MethodInfo method)Строка 837	C#
System.Linq.Expressions.dll!System.Linq.Expressions.Expression.AndAlso(System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Reflection.MethodInfo method)Строка 1336	C#
System.Linq.Expressions.dll!System.Linq.Expressions.Expression.MakeBinary(System.Linq.Expressions.ExpressionType binaryType, System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, bool liftToNull, System.Reflection.MethodInfo method, System.Linq.Expressions.LambdaExpression conversion)Строка 926	C#
System.Linq.Expressions.dll!System.Linq.Expressions.Expression.MakeBinary(System.Linq.Expressions.ExpressionType binaryType, System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, bool liftToNull, System.Reflection.MethodInfo method)Строка 886	C#

https://github.com/dotnet/corefx/blob/f7539b726c4bc2385b7f49e5751c1cff2f2c7368/src/System.Linq.Expressions/src/System/Linq/Expressions/BinaryExpression.cs#L827-L838

It is possible change the BinaryExpression.AndAlso for allow my simple scenario?

As I understand, same problem will be with OrOlse expression...


Also, I want to create 'AndAlso' expression, which will use method:

private static Nullable<Boolean> Exec_V_V(Nullable<Boolean> a,Nullable<Boolean> b)

Thanks.

@svick
Copy link
Contributor

svick commented Mar 16, 2019

As far as I can tell, you can't create an AndAlso expression for Boolean (or Nullable<Boolean>) with a custom method. That overload is meant for custom types with overloaded operator & (and also overloaded operator true and operator false).

What are you trying to achieve? Would it make sense for you to use a custom boolean type instead of Boolean?

@dmitry-lipetsk
Copy link
Author

I write data provider for EFCore (translator of C# to SQL).

I want to transform generated expression tree - I can change the node arguments and node methods.

Of course, I may transform "AndAlso" node to generic MethodCall node, but in this case I should rewrite lots of EFCore code (optimizer / SQL-generator).

I really not understand a current limitation of BinaryExpression.AndAlso.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the Future milestone Feb 1, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@cston
Copy link
Member

cston commented Jul 7, 2020

@dmitry-lipetsk, as @svick mentioned, the overloads of AndAlso() and OrElse() that take a MethodInfo are intended to support AndAlso and OrElse for custom types. When a non-null method is included, the compiled expression uses the op_False() and op_True() methods defined in the same type to skip evaluation of the second argument when possible. The Exception thrown for missing operators is the expected behavior.

Please note, we are limiting changes to System.Linq.Expressions to addressing significant bugs and regressions. We are unlikely to take other changes at this time. See README.md.

@cston cston removed the untriaged New issue has not been triaged by the area owner label Jul 7, 2020
@dotnet-policy-service dotnet-policy-service bot added backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity labels Jan 6, 2025
@dmitry-lipetsk
Copy link
Author

I think, It is a not actual issue not only to me but at all.

If I rememeber correctly, I used MethodCall nodes to solve this problems.

@dotnet-policy-service dotnet-policy-service bot removed no-recent-activity backlog-cleanup-candidate An inactive issue that has been marked for automated closure. labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants