Skip to content
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

Public API design for readonly properties and events in C# #34213

Open
RikkiGibson opened this issue Mar 18, 2019 · 2 comments
Open

Public API design for readonly properties and events in C# #34213

RikkiGibson opened this issue Mar 18, 2019 · 2 comments
Assignees
Labels
Area-Compilers Bug Concept-API This issue involves adding, removing, clarification, or modification of an API.
Milestone

Comments

@RikkiGibson
Copy link
Contributor

RikkiGibson commented Mar 18, 2019

There's a bit of public API that should be added to symbols for the readonly members feature.

So far the following API has been added to MethodSymbol (handwaving a bit):

/// <summary>
/// Indicates whether the method is declared readonly, i.e.
/// whether 'this' is readonly in the scope of the method.
/// See also <see cref="IsEffectivelyReadOnly"/>
/// </summary>
internal abstract bool IsDeclaredReadOnly { get; }

/// <summary>
/// Indicates whether the method is effectively readonly,
/// by either the method or the containing type being marked readonly.
/// </summary>
internal bool IsEffectivelyReadOnly => ...;

It's also possible for properties or property accessors to have readonly modifiers.

public readonly int Prop1
{
    // both accessors are 'readonly'
    get => this._store["Prop1"];
    set { this._store["Prop1"] = value; }
}
public int Prop2
{
    readonly get => this._prop2;
    set { this._prop2 = value; }
}

If users of the compiler APIs want to know if a property was declared readonly, or just its accessor, it could be necessary to add new methods to IPropertySymbol. The trouble is that ReadOnly properties already have a meaning in VB and in the existing property APIs: it means there is no set accessor.

This means that just copying the APIs from MethodSymbol to PropertySymbol is likely to cause confusion. We need a path forward where users can determine these facts about C# properties without causing confusion about VB properties or confusion with the existing API.

@RikkiGibson RikkiGibson added Concept-API This issue involves adding, removing, clarification, or modification of an API. Area-Compilers labels Mar 18, 2019
@RikkiGibson RikkiGibson added this to the 16.1 milestone Mar 18, 2019
@jaredpar jaredpar added the Bug label Mar 19, 2019
@RikkiGibson
Copy link
Contributor Author

We've decided that properties in metadata will never have the IsReadOnlyAttribute--only methods will (including accessors). Therefore it might be reasonable to let only methods have new API related to the readonly members feature.

@RikkiGibson RikkiGibson changed the title Public API design for readonly properties in C# Public API design for readonly properties and events in C# Apr 12, 2019
@RikkiGibson RikkiGibson reopened this Apr 12, 2019
@RikkiGibson
Copy link
Contributor Author

It seems reasonable that IEventSymbol should have an bool IsReadOnly property. But it's hard to be consistent across the different kinds of members that support readonly. @jasonmalinowski

@jcouv jcouv modified the milestones: 16.1, 16.2 Apr 23, 2019
@jcouv jcouv modified the milestones: 16.2, 16.3 Jun 19, 2019
@jcouv jcouv modified the milestones: 16.3, Compiler.Next Jul 10, 2019
@jaredpar jaredpar modified the milestones: Compiler.Next, Backlog Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Concept-API This issue involves adding, removing, clarification, or modification of an API.
Projects
None yet
Development

No branches or pull requests

3 participants