C-sharp getField usage

problem description

while learning the c-sharp project, I encountered such a statement FieldInfo field = base.GetType () .GetField (base2.Tag.ToString (), BindingFlags.NonPublic | BindingFlags.Instance);

the environmental background of the problems and what methods you have tried

looked up a lot, probably similar to converting objects into dictionaries, which should be done in the version before 03

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

could you tell me the role of each function in the whole process, and how to add the add method of the analogy dictionary? Thank you

Mar.24,2022

Instead of turning the object into a dictionary,

gets the metadata of the field (field) and its related information, which is presented as the FieldInfo class. In your example, you get the metadata for base2.Tag , which is then stored in the field variable.

first get the metadata of the base class through base.GetType () , and then get the metadata of base2.Tag through GetField (base2.Tag.ToString ()) ). BindingFlags.NonPublic | BindingFlags.Instance is a modifier that specifies base2.Tag , and so on.

(Chinese is not very good. Sorry)

Menu