Reputation: 681
I want to invoke the method ICompiledQuery IProvider.Compile(Expression query)
defined in System.Data.Linq.SqlClient.SqlProvider
class.
But the IProvider
interface is internal, so I can not do the cast. Is there any way to invoke the method?
Upvotes: 0
Views: 83
Reputation: 157048
You can use reflection to get the method and invoke it.
// Some test stuff, replace this with your own.
Expression e = null;
SqlProvider p = new SqlProvider();
// Get the IProvider interface
var iProvider = typeof(SqlProvider).FindInterfaces((t, o) => t.FullName == "System.Data.Linq.Provider.IProvider", null).FirstOrDefault();
if (iProvider != null)
{
// Get the Compile method on the interface
MethodInfo m = iProvider.GetMethod("Compile");
// Call it!
var output = m.Invoke(p, new object[] { e });
}
Upvotes: 1