Aliasing a generic interface with a using alias directive

Ernest3.14

I am aware that it's not possible to alias a generic type (e.g. using Foo = Dictionary; is invalid), but that the generic type on the right must be closed (e.g. using Foo = Dictionary<int, string>; will work).

However, it seems like it's invalid to alias an IDictionary<string, object>--instead, the alias must be for just the interface IDictionary. The error I get is "CS0308: The non-generic type 'IDictionary' cannot be used with type arguments." Is there a way to alias this entire thing? (Or a better way to achieve what I want?)

A common thing I do in my API is for functions to take an IDictionary<string, object>, and I'd like to do something akin to using ParsedObjects = IDictionary<string, object>;. In fact, I'd like to be able to declare:

using ParsedObjectsHandler = Func<Interaction, object, IDictionary<string, object>, Task>;

(But I am willing to settle for just the former.)

Ernest3.14

Edit: Although the below answer solves the question (and I'm leaving it up as I could not find the info anywhere else), I did go with V.Lion's suggestion in the comments to define my own delegate type instead.


The issue was that I was attempting to use System.Collections.IDictionary instead of System.Collections.Generic.IDictionary<TKey, TValue>. Using the latter worked just fine, i.e.:

using ParsedObjects = System.Collections.Generic.IDictionary<string, object>;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Using generic interface in a generic class

Using generic in the interface

Generic function using an interface

using generic collections with an interface

Defining a type alias using nested generic parameters

Using recursive type alias in generic results in error

How to create a specific alias based on a generic typescript interface

Create a factory by using a generic interface

Using an Interface for Collection<> generic type

building view using a generic interface

Aliasing interface property

Implementing generic interface with type parameters using deftype

Implement abstract factory using generic class and interface

Using Typescript to force generic constraint for interface?

Injecting an implementation of a generic interface subtype using Guice

Using where constraints with generic interface or class

Using the Data.Vector.Generic interface

registering classes implementing a generic interface using ninject

Passing around generic objects using an interface?

Generic type lost when using a nested interface

Using interface realization thru generic class

PHP Aliasing/Importing: Global Access or Alias?

Using an interface to communicate back to a Generic Type class that manages objects with this interface

Implementing generic methods from an interface using another interface

C# Interface: Handling instance classes using generic interface

Generic Interface

Generic interface parameters in a generic interface

Type aliasing for multiple traits with generic types

Generic with a type alias