Using Reflection to Manipulate Object State

The Reflection API provides the ability to manipulate an object's state, meaning its properties and fields. Using the Reflection API, you can call property accessors as well as directly change the value of an object's fields.

The two classes that represent fields and properties are the FieldInfo class and the PropertyInfo class, respectively. As with most of the reflection classes, you first have to search and discover a FieldInfo or PropertyInfo object before it can be invoked. Again, the Type class provides methods for discovering both fields and properties.

Discovering a Type's Field Information by Using the GetFields method

The Type.GetFields method has two overloads. One overload takes no parameters ...

Get Microsoft® .NET Compact Framework Kick Start now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.