You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to submit a feature request to add support for implicit operators.
To my understanding, implicit operators are only supported for booleans at the moment. We have a use case were we need to support implicit operators to cast from and to a structure.
We would like to be able to run the following example:
classProgram{staticvoidMain(string[]args){varparser=newExpressionParser([],"MyMethods.UsesMyStruct(\"Foo\")",[],newParsingConfig());varexpression=parser.Parse(typeof(MyStruct));varlambda=Expression.Lambda<Func<MyStruct>>(expression);varmethod=lambda.Compile();varresult=method();// result == MyStruct with Value = "Foo"}[DynamicLinqType]publicstaticclassMyMethods{publicstaticstringUsesMyStruct(MyStructmyStruct){returnmyStruct.Value;}}publicreadonlystructMyStruct(stringvalue){privatereadonlystring_value=value;publicstaticimplicitoperatorMyStruct(stringvalue){returnnewMyStruct(value);}publicstaticimplicitoperatorstring(MyStructmyStruct){returnmyStruct._value;}publicstringValue=>_value;}}
In plain C# this is also possible:
stringresult=MyMethods.UsesMyStruct("foo");
Running the example above results in the following exception:
Unhandled exception. No applicable method 'UsesMyStruct' exists in type 'MyMethods' (at index 10)
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMemberAccess(Type type, Expression expression, String id)
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseTypeAccess(Type type, Boolean getNext)
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIdentifier()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimaryStart()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseArithmetic()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAdditive()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseShiftOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator()
at System.Linq.Dynamic.Core.Parser.ExpressionParser.Parse(Type resultType, Boolean createParameterCtor)
The text was updated successfully, but these errors were encountered:
I would like to submit a feature request to add support for implicit operators.
To my understanding, implicit operators are only supported for booleans at the moment. We have a use case were we need to support implicit operators to cast from and to a structure.
We would like to be able to run the following example:
In plain C# this is also possible:
Running the example above results in the following exception:
The text was updated successfully, but these errors were encountered: