リフレクションを介して「内部」コードを実行する方法はありますか?
以下にプログラム例を示します。
using System;
using System.Reflection;
namespace ReflectionInternalTest
{
class Program
{
static void Main(string[] args)
{
Assembly asm = Assembly.GetExecutingAssembly();
// Call normally
new TestClass();
// Call with Reflection
asm.CreateInstance("ReflectionInternalTest.TestClass",
false,
BindingFlags.Default | BindingFlags.CreateInstance,
null,
null,
null,
null);
// Pause
Console.ReadLine();
}
}
class TestClass
{
internal TestClass()
{
Console.WriteLine("Test class instantiated");
}
}
}
通常、テストクラスの作成は完全に機能しますが、リフレクションを介してインスタンスを作成しようとすると、コンストラクターが見つからないことを示す missingMethodException エラーが発生します (これは、アセンブリの外部から呼び出そうとした場合に発生することです)。
これは不可能ですか、それとも私ができる回避策はありますか?