-
Notifications
You must be signed in to change notification settings - Fork 306
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
ObservableProperty and access modifiers #291
Comments
This is not supported and not planned. We want to support this properly in C# 12 via partial properties. For now the plan is to work on a proposal for that to add to the working set, and I don't think it'd be a good idea to hack a clunkier alternative for this just for the short term until C# 12 was out (which would be november 2023). That would also solve a whole lot of other problems related to the fact we're currently using fields in the first place 🙂 |
@Sergio0694 That's too bad, because right now, we cannot use the |
C# 12 should work on downlevel projects just fine (eg. see https://github.com/Sergio0694/PolySharp). |
Well, you never know who will use or touch the code. Making the setter explicitly private is being done on purpose for good reason. Making the setter public comes with a risk and incurs technical debt, because making the pending change once a proper solution is available must not be forgotten. You're right that compiler features should be backwards compatible with existing projects as long as no runtime changes are required. Still, I don't think that this should be dependent on a C# language version if it could be solved with Source Generators and Analyzers already now. Don't get me wrong, I understand your reasoning and it has its merit. I'm just unhappy about the fact that I cannot convert certain properties to use Source Generators unless I make changes that affect the behavior and the API of the existing code (if we consider a public setter of a public property an API). |
Private properties have been posponed till C# 14. Please reconsider this issue. This is somewhat of a bummer. As @ewerspej pointed out, currently Most concise way I can think of: private MyType _MyType;
public MyType
{
get => _MyType;
private | protected set => SetProperty(ref _MyType, value);
} |
You don't need C# 14, you can use them today if you set the language version to preview. See the announcement blog post. I'm not planning on adding new features to |
Overview
If I do this:
A
Title
property is auto generated where bothget
andset
is public. What if you want to limit the access onset
? It would be nice of you could define the access modifier in theObservableProperty
constructor.Usage example
Maybe like this:
This would be
Title
property is auto generated whereset
is internal.Breaking change?
No
Additional context
No response
Help us help you
No, just wanted to propose this
The text was updated successfully, but these errors were encountered: