Add initialiser to property syntax #1507
Replies: 7 comments
-
I'd absolutely hate for the compiler to bless one particular mechanism, like |
Beta Was this translation helpful? Give feedback.
-
@jnm2 i'm not proposing the mechanism only the behaviour, this is just some syntactic sugar to remove boiler plate code same as
for a much simpler and easier to read syntax, as you pointed out there are other ways of doing this than with the lazy but a quick and simple way of doing |
Beta Was this translation helpful? Give feedback.
-
it is another way to do the same, I mean this is good but I cannot see a real new value to C# |
Beta Was this translation helpful? Give feedback.
-
@Mteheran you could say the same about all the recent changes the the language, |
Beta Was this translation helpful? Give feedback.
-
Except allow you to write such code in a synchronous imperative style which makes such things as error handling, looping, etc. about a trillion times easier. If anything I think My problem with proposals like lazy initialization is that they imply a lot of policy concerns that end up implemented in exactly one way which would make the feature non-applicable in a lot of scenarios or they require a lot of additional syntax to capture those concerns. |
Beta Was this translation helpful? Give feedback.
-
Agreed with the points @HaloFour makes. But I could get on board with something like this: public int Progress { get; set; } using new Lazy<int>(0);
T Get<T>();
void Set<T>(T t); This is even more powerful. It doesn't bind the language to one approach for lazy properties. And it doesn't have to relate to lazy loading at all. |
Beta Was this translation helpful? Give feedback.
-
@HaloFour that is exactly the point i was making, they didn't DO anything new but the results doing it in a different way (ie of adding it to the language spec) was to make it much easier and more fluid to do a previously laborious and difficult task that has resulted in a vast improvement. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is a feature request
currently when creating a property you have get and set option
ie
the feature that i would like is to have the ability to specify an initialiser
ie
this would allow lazy loading
so would be the equivalent of
this would allow for the property to be set once to a default on the first read, but if set before being read initialisation wouldn't occur, this would promote the use of lazy loading plus simplifying the use
Beta Was this translation helpful? Give feedback.
All reactions