0

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
  • 1,012
  • 11
  • 21
  • 1
    Have you considered using delegates? You can define `ParsedObjectsHandler` delegate type with the signature you mentioned and use that directly without needing more verbose built-in generic `Func` delegates. – V.Leon Dec 02 '22 at 06:52
  • That sounds interesting... I'll take a look at that – Ernest3.14 Dec 02 '22 at 10:10
  • @V.Leon thank you, defining a new delegate type was the way to go. :D – Ernest3.14 Dec 03 '22 at 12:33

1 Answers1

0

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>;
Ernest3.14
  • 1,012
  • 11
  • 21