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

"Create and assign field" option disappears when "initialize property" is offered #76565

Open
jnm2 opened this issue Dec 25, 2024 · 2 comments
Open
Labels
untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@jnm2
Copy link
Contributor

jnm2 commented Dec 25, 2024

Version Used: Visual Studio 17.13.0 Preview 2.1

using System;
using System.Collections.Generic;
using System.Collections.Immutable;

class C<TKey, TItem> // : IReadOnlyDictionary<TKey, TItem>
{
    public C(ImmutableArray<TItem> items, ImmutableArray<TKey> keys)
    {
    }

    // Originally added via "Implement IReadOnlyDictionary<TKey, Item>"
    public IEnumerable<TKey> Keys => throw new NotImplementedException();
}

On the constructor parameter for keys, there is no "Create and assign field 'keys'" like there is for items. Instead, only "Initialize property 'Keys'":

using System;
using System.Collections.Generic;
using System.Collections.Immutable;

class C<TKey, TItem> // : IReadOnlyDictionary<TKey, TItem>
{
    public C(ImmutableArray<TItem> items, ImmutableArray<TKey> keys)
    {
        Keys = keys;
    }

    // Originally added via "Implement IReadOnlyDictionary<TKey, Item>"
    public IEnumerable<TKey> Keys { get; }
}

This is not desirable because the public Keys member is intended to remain IEnumerable<TKey> to implement the interface, but the class itself will want to access a field as ImmutableArray<TKey>.

It would be great to continue to have the option to create the field, beside the option to initialize the Keys property.

Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 25, 2024
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

1 participant