Table of Contents

Class PropertyRegistry

Namespace
Icy.Data.Markup
Assembly
IcyUI.dll

Stores the IPropertyStore for every type whose registered properties have been resolved.

public class PropertyRegistry : KeyedCollection<Type, IPropertyStore>, IList<IPropertyStore>, ICollection<IPropertyStore>, IReadOnlyList<IPropertyStore>, IReadOnlyCollection<IPropertyStore>, IEnumerable<IPropertyStore>, IList, ICollection, IEnumerable
Inheritance
PropertyRegistry
Implements
Inherited Members
Extension Methods

Remarks

A registry is an ordinary instance, not a singleton: it is a service on ReflectionConfiguration alongside IAssemblyResolver and ITypeConverter, so a configuration can be isolated from the rest of the process (tests being the common case). Default is the shared registry everything uses unless told otherwise.

All access for a given object must go through one registry. Two registries resolve the same property to two different IPropertyReference instances, and each reference keeps its own value-precedence bookkeeping - so mixing them would split an object's Local/Style/VisualState/Animation contributions across two tables and compute the wrong effective value. To make that hard to get wrong, every DependencyObject captures its registry once at construction (PropertyRegistry), and For(object) is the way to reach the right registry for an arbitrary target.

Constructors

PropertyRegistry()

Initializes a new instance of the PropertyRegistry class with no resolved types.

public PropertyRegistry()

Remarks

Prefer Default unless isolation is actually needed - a fresh registry re-scans every type it is asked about, and objects must not be shared across registries (see the remarks on PropertyRegistry).

Properties

Current

Gets the registry currently in scope - the one set by the innermost active UseScope(PropertyRegistry), or Default when none is active.

public static PropertyRegistry Current { get; }

Property Value

PropertyRegistry

Remarks

This is what a newly constructed DependencyObject captures, and what resolution falls back to when there is no object to ask.

Default

Gets the process-wide default registry, used whenever no other registry is in scope.

public static PropertyRegistry Default { get; }

Property Value

PropertyRegistry

TypeConverter

Gets or sets the type converter used to coerce values contributed to this registry's properties from a possibly-mismatched source type (a markup attribute string, most commonly) into each property's real type.

public ITypeConverter TypeConverter { get; set; }

Property Value

ITypeConverter

Remarks

Kept alongside Default/Current rather than reached only through TypeConverter, because Animation only ever has a target object to work from - going through For(object) is the same pattern Animation's constructor already uses to reach the right registry, so this reaches the right converter the same way, without adding a new ambient service or a new project reference from Icy.Animations.

Methods

For(object)

Gets the registry that owns target's property references.

public static PropertyRegistry For(object target)

Parameters

target object

The object whose registry is needed.

Returns

PropertyRegistry

target's own registry when it is a DependencyObject; otherwise Current.

Remarks

Use this instead of Current whenever a target object is available - it is what keeps an object's property access on the single registry it was built against (see the remarks on PropertyRegistry).

GetKeyForItem(IPropertyStore)

When implemented in a derived class, extracts the key from the specified element.

protected override Type GetKeyForItem(IPropertyStore item)

Parameters

item IPropertyStore

The element from which to extract the key.

Returns

Type

The key for the specified element.

GetPropertyStore(Type)

Retrieves the property store for a specific type, creating and registering the default reflection-based store for it on first request if none has been registered yet.

public IPropertyStore GetPropertyStore(Type type)

Parameters

type Type

The type for which to retrieve the property store.

Returns

IPropertyStore

The property store associated with the specified type.

Remarks

Call RegisterPropertyStore(IPropertyStore) ahead of time for a type if it needs a custom IPropertyStore implementation instead of the default reflection-based one.

RegisterPropertyStore(IPropertyStore)

Registers a property store for a specific type.

public void RegisterPropertyStore(IPropertyStore propertyStore)

Parameters

propertyStore IPropertyStore

The property store to register.

UseScope(PropertyRegistry)

Makes registry the Current registry until the returned scope is disposed.

public static IDisposable UseScope(PropertyRegistry registry)

Parameters

registry PropertyRegistry

The registry to use for the duration of the scope.

Returns

IDisposable

A scope that restores the previous Current registry when disposed.

Remarks

Scopes flow with the async context and nest. Objects constructed inside a scope keep that scope's registry for their whole lifetime, so they stay consistent after it ends.