"Create and assign field" option disappears when "initialize property" is offered #76565
Open
Description
opened on 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.
Activity