Code Monkey home page Code Monkey logo

readonlycollectioninterfaces's Introduction

Testing implementing read-only collection interfaces

This repo tests what would happen if we were to implement the read-only interfaces from the mutable interfaces. To simulate this, there are three projects:

  • Interfaces. First, this repo re-defines the existing interfaces using a My prefix. The Interfaces project is multi-targeted defining the interfaces as-is for .NET 7.0 and extending the read-only flavors from the mutable ones for .NET 8.0.

  • Implementations. Then there is an Implementations project that only targets .NET 7.0, thus simulating existing user code that was built for today's world where the mutable interfaces aren't extending the read-only ones.

  • Application. Finally, there is an Application project that is targeting .NET 8.0, thus simulating what happens when existing code is loaded and run on a newer runtime where the mutable interfaces extend the read-only ones.

Note

We only use net7.0 and net8.0 for convenience of testing with the current .NET SDK, which is .NET 8.0. There is no goal to port this to .NET 8.0. The new interface shape is for .NET 9.0 and later only.

Interfaces

interface IMyReadOnlyCollection<out T> : IEnumerable<T> {}
interface IMyReadOnlyList<out T> : IMyReadOnlyCollection<T> {}
interface IMyReadOnlyDictionary<TKey, TValue> : IMyReadOnlyCollection<KeyValuePair<TKey, TValue>> {}
interface IMyReadOnlySet<T> : IMyReadOnlyCollection<T> {}

#if NET7_0

// Current shape, mutable interfaces don't extend read-only ones
public interface IMyCollection<T> : IEnumerable<T> {}
public interface IMyList<T> : IMyCollection<T> {}
public interface IMyDictionary<TKey, TValue> : IMyCollection<KeyValuePair<TKey, TValue>> {}
public interface IMySet<T> : IMyCollection<T> {}

#elif NET8_0

// Desired shape, mutable interfaces do extend read-only ones
interface IMyCollection<T> : IMyReadOnlyCollection<T> {}
interface IMyList<T> : IMyCollection<T>, IMyReadOnlyList<T> {}
interface IMyDictionary<TKey, TValue> : IMyCollection<KeyValuePair<TKey, TValue>>, IMyReadOnlyDictionary<TKey, TValue> {}
interface IMySet<T> : IMyCollection<T>, IMyReadOnlySet<T> {}

#endif

Implementations

The most complex case we could think of to create a shared diamond is a KeyedCollection that implements both IMyDictionary<,> and IMyList<>:

public class MyKeyedCollection : IMyDictionary<string, string>, IMyList<string> {}

readonlycollectioninterfaces's People

Contributors

terrajobst avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.