Il est visible dans le constructeur dans Reflector.
class Foo { private string _secret = @"all your base are belong to us"; }
se traduit par le constructeur ayant
public Foo() { this._secret = "all your base are belong to us"; }
qui est visible dans le réflecteur sous Foo
dans la méthode .ctor
.
Vous pouvez également consulter ces informations en ildasm
(livré avec Microsoft Visual Studio) dans 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
Enfin, si quelqu'un connaît le nom de votre type et le nom de votre domaine privé, vous pouvez obtenir la valeur en tant que telle:
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
Bien sûr, je peux toujours voir tous vos champs privés avec
var fields = typeof(Foo).GetFields(
BindingFlags.Instance | BindingFlags.NonPublic
);
Je pensais que c'était là, mais je ne pouvais pas le trouver. Merci beaucoup! –