API ドキュメントから、ReflectionOnlyGetType が GetType と同じように型を返すことを理解しています。違いは、ReflectionOnlyGetType では、型が実行ではなくリフレクションのみに読み込まれることです。
では、なぜこれが機能するのでしょうか。
Type t = Type.ReflectionOnlyGetType("System.Collections.Generic.List`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", false, false);
ConstructorInfo[] cis = t.GetConstructors();
foreach (ConstructorInfo ci in cis)
{
if (ci.GetParameters().Length == 0)
{
// ! no arg constructor found! let's call it!
Object o = ci.Invoke(new Object[]{});
Console.WriteLine("But wait, it was supposed to be reflection only??");
Console.WriteLine(o.GetType().Name);
List<String> lli = (List<String>)o;
lli.Add("but how can this be?");
Console.WriteLine(lli.Count);
Console.WriteLine("I am doing a lot more than reflection here!");
}
}
私の質問は: 私はこのタイプのメンバーを反映する以上のことができるようです. タイプが「実行ではなくリフレクションのみにロードされる」と彼らが言うとき、私は「実行」を誤解しましたか? または、タイプが既に「ロード」されていて、mscorlib にあるためにここでロードされた場合、ReflectionOnlyGetType は別の (非反射のみの) タイプを返しますか? それとも全然違うものですか?