Replies: 20 comments
-
Is it not possible for the compiler to simply ignore the warning when it generates the field? public Foo LazyInstance => field ??= new Foo(42); // just don't report an initialization warning 4head
There's also a scenario in Blazor where you need to call a base method if you have some data changing outside of an event: public ModelType Model
{
get;
set
{
field = value;
StateHasChanged(); // forgetting this call will not re-render the component so the change won't be visible
}
} Sure, it's similar to the INPC example, but it's also proof that another case is out there. Additionally, can |
Beta Was this translation helpful? Give feedback.
-
Yes, that's how we're currently viewing it :) |
Beta Was this translation helpful? Give feedback.
-
Do we have any example of the use case and how to use And also, do the |
Beta Was this translation helpful? Give feedback.
-
See https://github.com/dotnet/csharplang/blob/master/proposals/function-pointers.md for function pointers. |
Beta Was this translation helpful? Give feedback.
-
@333fred Thank you very much |
Beta Was this translation helpful? Give feedback.
-
#133 is the proposal that provides backing fields of different types, and provides for multiple fields scoped to a property. It also provides the same for events. I mentioned this in the comments, that #133 and #140 are not exclusive. Together they cover simple and slightly more complex cases. |
Beta Was this translation helpful? Give feedback.
-
the |
Beta Was this translation helpful? Give feedback.
-
@huoshan12345 Yes, that's the intent. |
Beta Was this translation helpful? Give feedback.
-
This would be extremely useful. When auto-implemented properties can't be used, I'd venture to guess the logic goes in the setter and the getter is just a simple read probably > 90% of the time. Cutting the extra noise off of that would be great. |
Beta Was this translation helpful? Give feedback.
-
The thought of being able to simplify
Is incredibly appealing, and has me excited to see this usable. Would I be wrong to think that I could also write |
Beta Was this translation helpful? Give feedback.
-
@DaZombieKiller I think source generators might be a better solution to this. If we get partial properties this might be possible: [NotifyPropertyChanged]
public partial string Property { get; set } |
Beta Was this translation helpful? Give feedback.
-
@YairHalberstadt I absolutely agree. Although I'd be satisfied with using the |
Beta Was this translation helpful? Give feedback.
-
Source generators are planned for C# 9, although they're still in a prototype phase. |
Beta Was this translation helpful? Give feedback.
-
Not according to the Milestone tag on it. #107 |
Beta Was this translation helpful? Give feedback.
-
I must say these notes are remarkably prescient for being over 1800 years old. :) |
Beta Was this translation helpful? Give feedback.
-
Note that source generators are not replace/original. The source generator changes we're planning are really a compiler feature, not a language feature, so I wouldn't really call them part of C# 9. See https://github.com/dotnet/roslyn/blob/features/source-generators/docs/features/source-generators.md and https://github.com/dotnet/roslyn/blob/features/source-generators/docs/features/source-generators.cookbook.md. |
Beta Was this translation helpful? Give feedback.
-
Interesting. Is there an issue to discuss these changes specifically? Reading over those two documents, this feature strikes me as being a lot more similar to T4 templates than it is to the Pros:
Cons:
All in all I'm not convinced this proposed compiler feature as it stands currently really adds enough benefits over the current tooling. Even worse would be if the design made it more difficult to add true AOP to the language at some point in the future. |
Beta Was this translation helpful? Give feedback.
-
AOP is a non-goal. |
Beta Was this translation helpful? Give feedback.
-
For this feature. Is it a non-goal forever? I thought the part in the spec about "There are already well supported tools and techniques for achieving these kinds of operations, and the source generators proposal is not aimed at replacing them." was particularly hand-wavy, given one of the main reasons people wanted |
Beta Was this translation helpful? Give feedback.
-
Who can say? :) There's no one thinking about it currently. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
C# Language Design Notes for April 1, 2020
Function pointer design adjustments
field
keyword in propertiesBeta Was this translation helpful? Give feedback.
All reactions