0

I have a generic class:

public Company.DataAccess.Repository<Model>

And I also have a global Usings.cs file to centralize and DRY my using statements.

Now I want to create an alis for the Repository. But this line does not work:

global using Repo = Company.DataAccess.Repository;

C# compiler complains that:

error CS0305: Using the generic type 'Repository' requires 1 type arguments

Does this mean that I can't define aliases for my generic types?

Hossein Fallah
  • 1,859
  • 2
  • 18
  • 44
  • 1
    `Company.DataAccess.Repository`, if it names a type, names a non-generic type called `Repository`. That you happen to have a generic type called `Repository` in that same namespace is of no relevance - the only "association" between those types is one in your own mind. – Damien_The_Unbeliever Dec 10 '21 at 08:48
  • Never mind my earlier comments. As the duplicate link states, the using X=Y type aliasing doesn't support open generics. – Lasse V. Karlsen Dec 10 '21 at 12:31
  • This question specifically asks about a new language feature being global using. At the time of the answer that keyword did not exist yet. The answer probably still applies but an explanation why global using also does not work is in order. How can a question asking about a newer feature in .NET ever be a duplicate of a question answered years before global using existed ? – Philip Stuyck Feb 13 '23 at 07:10

0 Answers0