Type GetGenericParameterType(Type typeToQuery, Type genericInterfaceType)
{
return (from @interface in typeToQuery.GetInterfaces()
where @interface.IsGenericType && @interface.GetGenericTypeDefinition() == genericInterfaceType
select @interface.GetGenericArguments()[0]).FirstOrDefault();
}
}