Everything is achievable through technology

Getting the parameters of a generic type into a dictionary

public static Dictionary GetGenericParameters(Type type)
Dictionary result = new Dictionary();
Type[] tValues = type.GetGenericArguments();
Type[] tKeys = type.GetGenericTypeDefinition().GetGenericArguments();
if (tValues.Length == tKeys.Length)
for (int index = 0; index < tValues.Length; index++)
result.Add(tKeys[index].Name, tValues[index]);
return result;
foreach (KeyValuePair pair in GetGenericParameters(typeof(Tuple<string, int, Guid, StringBuilder, long, bool, Tuple>)))
Console.WriteLine("{0}: {1}", pair.Key, pair.Value);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s