Reflector のコンストラクターで表示されます。
class Foo { private string _secret = @"all your base are belong to us"; }
コンストラクタを持つことに変換されます
public Foo() { this._secret = "all your base are belong to us"; }
Foo
これは、メソッドの下のリフレクターに表示され.ctor
ます。
この情報は、ildasm
(Microsoft Visual Studio に同梱) にも表示されFoo::.ctor : void
ます。
.method public hidebysig specialname rtspecialname instance void .ctor() cil managed {
// Code size 19 (0x13)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldstr "all your base are belong to us"
IL_0006: stfld string Playground.Foo::_secret
IL_000b: ldarg.0
IL_000c: call instance void [mscorlib]System.Object::.ctor()
IL_0011: nop
IL_0012: ret
} // end of method Foo::.ctor
最後に、型の名前とプライベート フィールドの名前を知っている人がいる場合は、次のように値を取得できます。
object o = typeof(Foo).GetField(
"_secret",
BindingFlags.Instance | BindingFlags.NonPublic
).GetValue(f);
Console.WriteLine(o); // writes "all your base are belong to us" to the console
もちろん、私はいつでもあなたのすべてのプライベートフィールドを見ることができます
var fields = typeof(Foo).GetFields(
BindingFlags.Instance | BindingFlags.NonPublic
);