FieldAccessorGet Method

Gets the value of the field. For static fields the instance parameter is omitted (can be ).

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
C#
public Object? Get(
	Object? instance
)

Parameters

instance  Object
The instance that the field belongs to. Can be for static fields.

Return Value

Object
The value of the field.

Remarks

Getting the field for the first time is slower than the System.Reflection.FieldInfo.GetValue method but further calls are much faster.

  Tip

If you know the type of the field at compile time (and also the declaring type for instance fields), then you can use the generic GetStaticValue or GetInstanceValue methods for better performance.

Exceptions

InvalidOperationExceptionThis FieldAccessor represents a field of an open generic type.
ArgumentNullExceptionThis FieldAccessor represents an instance field and instance is .
ArgumentExceptionThe type of instance is invalid.
NotSupportedExceptionOn .NET Framework the code is executed in a partially trusted domain with insufficient permissions.

See Also