In Program During the design, we may write some underlying libraries, including some core classes, which usually encapsulate some private methods and private variables. When the program is not completed, we may need to debug it to check whether the defined class has any errors.
Of course, this library may also come from other developers.
We may check the private variables in the class during debugging.
My personal habit is to write a DLL that I think is more important to test it to verify its correctness.
Debugging is different from testing.
Debugging means you may not know the final running result of the program, and testing means you confirm the input, you can predict the output, so you can verify the final result.
There are a lot of reflection materials, so I will not specifically talk about how to view all the methods in a class. All the members have finished.
Suppose I already know the name of a private member and now there is an object of this type. What should I do if I want to know the value of a private member?
Let's take a look.CodeIt is easy to know how to view the private members of an object through reflection.
Type mytype = OBJ. GetType ();
Fieldinfo = Mytype. getfield ( " _ Usercouldexecutedt " , Bindingflags. nonpublic | Bindingflags. Instance | Bindingflags. Public );
If (Fieldinfo ! = Null )
{
String SS=(String) Fieldinfo. getvalue (OBJ );
Console. writeline (SS );
}
It's easy.