Class PropertyPath
Represents a static-typed property path.
public class PropertyPath : IPropertyPath, IReadOnlyPropertyPath
- Inheritance
-
PropertyPath
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
PropertyPath(string, Type, PropertyRegistry?)
Initializes a new instance of the PropertyPath class.
public PropertyPath(string path, Type typeContext, PropertyRegistry? registry = null)
Parameters
pathstringThe path to get the value by the property.
typeContextTypeInitial type to access the properties for.
registryPropertyRegistryThe registry to resolve registered properties through, or null to capture Current at construction time.
Remarks
The registry is captured once here and shared by every segment of the path, so a single path never straddles two registries. It is not re-resolved per call: a path built under one registry and then used against an object belonging to another still reads and writes through the captured registry's IPropertyReference, which would see a different set of precedence contributions - see the remarks on PropertyRegistry. Build paths in the same scope as the objects they target.
Properties
DisplayPath
Gets the path for this instance for the debug display.
protected string DisplayPath { get; }
Property Value
PathSegments
Gets the list of the part segments for this property path.
protected List<PropertyPath.PathSegment> PathSegments { get; }
Property Value
PropertyType
Gets the type of the last property in the chain.
public Type PropertyType { get; }
Property Value
Methods
DependsOn(string)
Determines whether a change of the specified property on the source object can change this path's value.
public virtual bool DependsOn(string propertyName)
Parameters
propertyNamestringThe name of the changed property, as reported by INotifyPropertyChanged.
Returns
- bool
true if the path starts with the specified property, or if it can't tell; otherwise, false. The default implementation always returns true.
Remarks
A Binding uses this to ignore change notifications for unrelated properties of its source, so they don't overwrite the text a user is typing.
GetValue(object)
Gets the value by calling the property chain for the specified source object.
public virtual object? GetValue(object source)
Parameters
sourceobjectAn object to retrieve value from.
Returns
- object
The value by the specified property path.
Remarks
Returns null when a value along the path is null, the same as a DynamicPropertyPath. Exceptions thrown by a getter itself propagate.
ParsePath(string, Type, PropertyRegistry?)
Gets the list of path segments for the specified property path.
protected static List<PropertyPath.PathSegment> ParsePath(string path, Type typeContext, PropertyRegistry? registry = null)
Parameters
pathstringThe path string to parse.
typeContextTypeThe type to get property info.
registryPropertyRegistryThe registry to resolve registered properties through, or null to use Current.
Returns
- List<PropertyPath.PathSegment>
The list of PropertyPath.PathSegment with all segments of the specified path.
Exceptions
- FormatException
Occurs if the indexer wasn't defined correctly.
SetValue(object, object?)
Sets the value by calling the property chain for the specified target object.
public virtual void SetValue(object target, object? value)
Parameters
Remarks
Does nothing when the object the last member is set on, or a value on the way to it, is null, the same as a DynamicPropertyPath. Exceptions thrown by a getter or the setter itself propagate.