Table of Contents

Class PropertyGridEntry

Namespace
Icy.Data
Assembly
IcyUI.dll

Describes a single property a PropertyGrid row edits - unifying an IPropertyReference-registered property and a plain reflected PropertyInfo behind one shape, since Target may be either.

public sealed class PropertyGridEntry
Inheritance
PropertyGridEntry
Inherited Members
Extension Methods

Remarks

Metadata comes entirely from standard System.ComponentModel/ System.ComponentModel.DataAnnotations attributes on the underlying property - see the design spec for why no new IcyUI attribute type was introduced for this.

Properties

Category

Gets the group this property is shown under - CategoryAttribute's value, or "Misc" when none is present.

public string Category { get; }

Property Value

string

DefaultValue

Gets the declared default, converted to PropertyType when the attribute stored another numeric type ([DefaultValue(40)] on a float). Meaningful only when HasDefaultValue is true.

public object? DefaultValue { get; }

Property Value

object

Description

Gets the property's description from DescriptionAttribute, or null.

public string? Description { get; }

Property Value

string

DisplayName

Gets the label to show for this property - DisplayNameAttribute's value, or Name when none is present.

public string DisplayName { get; }

Property Value

string

HasDefaultValue

Gets a value indicating whether the property declares a default through DefaultValueAttribute.

public bool HasDefaultValue { get; }

Property Value

bool

IsReadOnly

Gets a value indicating whether this property's editor should be disabled - either ReadOnlyAttribute says so explicitly, or the underlying property has no public setter.

public bool IsReadOnly { get; }

Property Value

bool

Name

Gets the underlying property's name.

public string Name { get; }

Property Value

string

PropertyType

Gets the underlying property's value type.

public Type PropertyType { get; }

Property Value

Type

Range

Gets the values this numeric property accepts, from RangeAttribute, or null when it declares none, isn't numeric, or declares a range that contains no values.

public ValueRange? Range { get; }

Property Value

ValueRange?

Methods

EnumerateFor(object)

Enumerates every browsable property on target's runtime type - properties registered via [RegisterReference] first, then every other public readable property found by plain reflection - grouped by Category in first-seen order.

public static IReadOnlyList<PropertyGridEntry> EnumerateFor(object target)

Parameters

target object

The object to enumerate properties for.

Returns

IReadOnlyList<PropertyGridEntry>

The resulting entries, grouped by Category.

Remarks

The two passes are deduplicated against each other by the reflected member itself - specifically by the (DeclaringType, Name) pair - rather than by the display string, so two distinct properties sharing one DisplayNameAttribute both survive, while a property found by both passes is emitted once.

The PropertyInfo instance itself can't serve as that key: the registered pass resolves a property through OwnerType (the property's declaring type), while the reflected pass resolves it off target's runtime type. For a registered property declared on a base class and merely inherited by a derived one, those are two different PropertyInfo objects (differing in ReflectedType) that reference equality - all HashSet<T> has for PropertyInfo - never unifies, so every such property would be listed twice. Keying on DeclaringType/Name unifies them while still keeping a derived property that shadows a base one via new distinct, since the two differ in DeclaringType.

GetValue(object)

Reads this property's current value from target.

public object? GetValue(object target)

Parameters

target object

The object to read the value from.

Returns

object

The property's current value.

TrySetValue(object, object?)

Attempts to write value to this property on target.

public bool TrySetValue(object target, object? value)

Parameters

target object

The object to write the value to.

value object

The value to assign.

Returns

bool

true if the value was written; false when IsReadOnly is true, the property has no setter, or the assignment threw (an incompatible value).

Validate(object?, out string?)

Checks a value against the property's declared rules before it's written.

public bool Validate(object? value, out string? reason)

Parameters

value object

The candidate value, already of PropertyType.

reason string

Why the value is rejected, when this method returns false.

Returns

bool