PropertyAccessorGet(Object, Object) Method

Gets the value of the property. For static properties the instance parameter is omitted (can be ). If the property is not an indexer, then indexParameters parameter is omitted.

Definition

Namespace: KGySoft.Reflection
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
C#
public Object? Get(
	Object? instance,
	params Object?[]? indexParameters
)

Parameters

instance  Object
The instance that the property belongs to. Can be for static properties.
indexParameters  Object
The parameters if the property is an indexer.

Return Value

Object
The value of the property.

Remarks

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

  Tip

If the property has no more than one index parameters and you know the type of the property at compile time (and also the declaring type for instance properties), then you can use the generic GetStaticValue or GetInstanceValue methods for better performance.

  Notes to Callers

If the property is a a non-readonly instance property of a value type, then the .NET Standard 2.0 version of this method defaults to use regular reflection to preserve possible mutations. To experience the best performance try to target .NET Standard 2.1 or any .NET Framework or .NET Core/.NET platforms instead.

Exceptions

ArgumentNullExceptionThis PropertyAccessor represents an instance property and instance is
-or-
This PropertyAccessor represents an indexed property and indexParameters is .
ArgumentExceptionThe type of instance or one of the indexParameters is invalid.
-or-
indexParameters has too few elements.
InvalidOperationExceptionThe PropertyAccessor represents a property of an open generic type.
NotSupportedExceptionThis PropertyAccessor represents a write-only property.
-or-
On .NET Framework the code is executed in a partially trusted domain with insufficient permissions.
PlatformNotSupportedExceptionYou use the .NET Standard 2.0 build of KGySoft.CoreLibraries and this PropertyAccessor represents a ref property.

See Also