
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
776
|
Chapter 13: Reflection
Type.GetFields method, only public fields are returned. If both the BindingFlags.
Public
and BindingFlags.NonPublic flags are passed to the Type.GetFields method,
the list of fields is expanded to include the protected, internal, protected internal, and
private fields of a type. Table 13-2 lists and describes each flag in the
BindingFlags enu-
meration.
Be aware that to examine or invoke nonpublic members, your assembly must have
the correct reflection permissions. The reflection permission flags, and what
PermissionSets they are included in by default, are listed in Table 13-3.
One other item to note is that when supplying a
BindingFlags set of flags for one of
the
Get* methods, you must always pass either BindingFlags.Instance or BindingFlags.
Static
in order to get any results back. If you pass just BindingFlags.Public, for
example, you will not find any results. You need to pass
BindingFlags.Public |
BindingFlags.Instance to get public instance results.
See Also
See the “BindingFlags Enumeration,” “Type Class,” “ConstructorInfo Class,” and
“FieldInfo Class” topics in the MSDN documentation.
Table 13-2. Relevant binding flag definitions
Flag name Definition
IgnoreCase Case sensitivity is turned off.
Instance Include all instance members when obtaining members of a ...