MakeGenericType Example

CSharp · Console

/Program.cs

using System;
using System.Linq;


public class Program
{
	public static void Main()
	{
		var paramType = typeof (string);
		var myMiscType = typeof (MyGeneric<>).MakeGenericType(paramType);
		Console.WriteLine(myMiscType.FullName);
		Console.WriteLine();

		var assembly = myMiscType.Assembly;
		var allTypesfromMyTypeAssembly = (
			from t in assembly.GetTypes()where typeof (Abase).IsAssignableFrom(t)select t);
		
		foreach (var t in allTypesfromMyTypeAssembly)
		{
			Console.WriteLine(t.FullName);  //My type is not in here
		}
	}

	public abstract class Abase {}

	public class MyGeneric<T> : Abase {}
	
}
;