Skip to content

Instantly share code, notes, and snippets.

@SeriousM
Created August 8, 2014 11:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeriousM/bf5d9558d4481538b7b7 to your computer and use it in GitHub Desktop.
Save SeriousM/bf5d9558d4481538b7b7 to your computer and use it in GitHub Desktop.
Extract Generic Type Definition in C#
void Main()
{
	GetTypeFromList(new List<string>()).Dump();
	GetTypeFromFunc((string s, int i) => true).Dump();
}

public Type GetTypeFromList<TType>(IEnumerable<TType> dummy)
{
	return typeof(TType);
}

public Type[] GetTypeFromFunc<T1, T2, TOut>(Func<T1, T2, TOut> dummy)
{
	return new [] { typeof(T1), typeof(T2), typeof(TOut) };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment