0

There are like 1000 posts telling me how to get a TypeName, like

Get type name without full namespace in C#

Get the type name

and many many more, and all are working fine, BUT I need to get the TypeName resolved with usings provided.

For example I have the following using:

using Foo = System.Collections.Generic;

and now the following call to get the name:

var x = typeof (Foo.List<>);
var y = x.Name;

I would like to get the output

Foo.List`1

instead of only

List`1

Is this possible, or is the only choice string manipulation?

Community
  • 1
  • 1
Rand Random
  • 7,300
  • 10
  • 40
  • 88

2 Answers2

5

using directives are a purely compile-time construct.

That is fundamentally impossible; the information you want does not exist at runtime.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
1

This is syntactic sugar for the C# language it's not a fundamental feature of .NET in and of itself.

Lloyd
  • 29,197
  • 4
  • 84
  • 98