Mono Class Library: System.Type Overview | Members

System.Type.GetField Method

Returns a System.Reflection.FieldInfo object reflecting the field that has the specified name and is defined in the type represented by the current instance.

public System.Reflection.FieldInfo GetField (string name)

Parameters

name
A string containing the name of the field to be returned.

Returns

A System.Reflection.FieldInfo object reflecting the field that is named name and is defined in the type represented by the current instance, if found; otherwise, null. If the selected field is non-public, the type represented by the current instance is from a loaded assembly and the caller does not have sufficient permission to reflect on non-public objects in loaded assemblies, 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.

Permissions

TypeReason
System.Security.Permissions.ReflectionPermissionRequires permission to retrieve information on non-public members of types in loaded assemblies. See System.Security.Permissions.ReflectionPermissionFlag.TypeInformation.

Exceptions

TypeReason
ArgumentNullExceptionname is null.

Remarks

The search for name is case-sensitive.

This version of Type.GetField(string, System.Reflection.BindingFlags) is equivalent to Type.GetField(string, System.Reflection.BindingFlags)( name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance ).

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.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0