Skip to content

Please add covariant version of dictionary interface #116952

Closed as not planned
Closed as not planned
@Thaina

Description

@Thaina

Please add interface with in / out keyword without TryGetValue and attach it to Dictionary so that we could make use for variant of it for other usage

Suppose we have

/// suppose C# has

public interface IVariantDictionary<in TKey,out TValue> { /* all common dictionary function possible to variant */ }

public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary
    , IReadOnlyDictionary<TKey, TValue>
    , IVariantDictionary<TKey,TValue>
    , ISerializable, IDeserializationCallback where TKey : notnull
{
/* current implementation*/
}

/// we can then

class Animal {}
class Dog : Animal {}

var dogs = new Dictionary<string,Dog>();

IVariantDictionary<string,Animal> animals = dogs;

Console.WriteLine("I have animal : " + animals.Count);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions