Table of Contents

Class PropertyInfoExtensions

Namespace
HeroKit.Properties
Assembly
HeroKit.dll

Provides helpers for reading and setting properties through reflection.

public static class PropertyInfoExtensions
Inheritance
PropertyInfoExtensions
Inherited Members

Methods

CanAssignValue(PropertyInfo, object?)

Checks whether a value can be assigned to the property without conversion.

public static bool CanAssignValue(this PropertyInfo property, object? value)

Parameters

property PropertyInfo

The property.

value object

The value to check. Null is assignable to reference types and nullable value types.

Returns

bool

True if the value can be assigned; otherwise false.

IsNullable(PropertyInfo)

Checks whether the property type is a nullable value type, such as int?.

public static bool IsNullable(this PropertyInfo property)

Parameters

property PropertyInfo

The property.

Returns

bool

True if the property type is Nullable<T>; otherwise false.

TrySetConvertedValue(PropertyInfo, object?, object?)

Converts a value to the property type and sets it on an instance.

public static bool TrySetConvertedValue(this PropertyInfo property, object? instance, object? value)

Parameters

property PropertyInfo

The property to set.

instance object

The instance that owns the property, or null for a static property.

value object

The value to convert and set.

Returns

bool

True if the value was converted and set; otherwise false.

Examples

typeof(Order).GetProperty("Quantity")!.TrySetConvertedValue(order, "42"); // order.Quantity == 42

Remarks

Conversion follows TryConvertTo<T>(object?, out T?). Null is set only on properties that accept null.