Replies: 3 comments
-
Just to mentioned, F# uses an attribute for this |
Beta Was this translation helpful? Give feedback.
-
This could be probably solved with more generall approach if C# allowed annotating expression bodied methods and properties with |
Beta Was this translation helpful? Give feedback.
-
With SourceGenerators this is now perfectly possible, 2 projects that are doing this already: Both projects are currently tied to EFCore however the same pattern may be used in a more generalized project. Having source generators in the mix, I don't see a direct need for having the need from the compiler to natively generate Expression Members. I've would suggest we close this issue. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Allow methods and properties to be usefully used in API's that take expression trees
Motivation
API's such as LINQ to entities use expression trees to convert C# code into queries on a remote database. However this can often lead to repeated code when using objects that have, properties that would if called from .NET be abstracted behind a property cannot be when used with API's that take Expression trees.
A specific example:
It would be nice if you could use the
Visible
property in both to ensure the code can be shared and changes in the way thatVisible
is defined are reflected in the database queries.e.g.
Proposal
If
Visible
were instead declared asThen if the method was called from normal C# code then it would act the same as before however if it is called in a context which generates expression trees then the contents of the property are inlined in the generated expression tree.
Beta Was this translation helpful? Give feedback.
All reactions