Skip to content

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

Open
@jnm2

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    untriagedIssues and PRs which have not yet been triaged by a lead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions