Note that there are some explanatory texts on larger screens.

plurals
  1. POList closed types that runtime has created from open generic types
    text
    copied!<p>When I list all the types in the current AppDomain, I see my generic types with the generic placeholders. However, if I instantiate my generic types with a type and then list all the types in the appDomain, I don't see the newly created closed types.</p> <p>In the example below, the output is only:</p> <pre><code>Foo`1[T] </code></pre> <p>I'm looking for the closed type:</p> <pre><code>Foo`1[System.Int32] </code></pre> <p>Is there a way to see the closed types that the runtime has created for me based on my open generic types?</p> <pre><code>class Foo&lt;T&gt; { } class Program { static void Main(string[] args) { var tmp = new Foo&lt;int&gt;(); ListTypes(); } private static void ListTypes() { var types = from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where type.Name.Contains("Foo") select type; foreach (var type in types) Console.WriteLine(type.ToString()); } } </code></pre> <p>I have also tried finding all types by the generic argument in hopes of discovering the closed type.</p> <pre><code>class Foo&lt;T&gt; { } class Bar { } class Program { static void Main(string[] args) { var tmp = new Foo&lt;Bar&gt;(); ListTypes(); } private static void ListTypes() { var types = from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where type.IsGenericType &amp;&amp; type.GetGenericArguments().Contains(typeof(Bar)) select type; foreach (var type in types) Console.WriteLine(type.ToString()); } } </code></pre> <p><em>This is just to satisfy my curiosity.</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload