Returns a System.Reflection.FieldInfo object reflecting the field that has the specified name, is defined in the type represented by the current instance, and matches the specified binding constraints.
- name
- A string containing the name of the field to be returned.
- bindingAttr
- A bitwise combination of System.Reflection.BindingFlags values that control the binding process. If zero is specified, this method returns null .
A System.Reflection.FieldInfo object reflecting the field that is named name, is defined in the type represented by the current instance, and matches the constraints of bindingAttr. If a field matching these criteria cannot be found, returns null. If the field is not public, the current type is from a loaded assembly, and the caller does not have sufficient permission, returns null.
If the current instance represents a generic type, this method returns the System.Reflection.FieldInfo with the type parameters replaced by the appropriate type arguments.
Type Reason System.Security.Permissions.ReflectionPermission Requires permission to retrieve information on non-public members of types in loaded assemblies. See System.Security.Permissions.ReflectionPermissionFlag.TypeInformation.
Type Reason ArgumentNullException name is null.
The following System.Reflection.BindingFlags are used to define which fields to include in the search:
- Specify either System.Reflection.BindingFlags.Instance or System.Reflection.BindingFlags.Static to get a return value other than null.
- Specify System.Reflection.BindingFlags.Public to include public fields in the search.
- Specify System.Reflection.BindingFlags.NonPublic to include non-public fields (that is, private and protected fields) in the search.
The following System.Reflection.BindingFlags values can be used to change how the search works:
- System.Reflection.BindingFlags.DeclaredOnly to search only the fields declared in the type, not fields that were simply inherited.
- System.Reflection.BindingFlags.IgnoreCase to ignore the case of name.
Note: For more information, see System.Reflection.BindingFlags.If the current instance represents an unassigned type parameter of a generic type or method, this method searches the fields of the class constraint; the fields of all interface constraints; and the fields of any interfaces inherited from class or interface constraints.
Operation
As described above.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0