Skip to content

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

@jnm2

Description

@jnm2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEhelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Projects

    Status

    Completed

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions