Skip to content

Class PrecompiledPropertyDescriptor<TTarget, TProperty>

Definition

Namespace: StardewUI.Framework.Descriptors
Assembly: StardewUI.dll

Statically-typed implementation of an IPropertyDescriptor<T> with predefined attributes.

public class PrecompiledPropertyDescriptor<TTarget, TProperty> : 
    StardewUI.Framework.Descriptors.IPropertyDescriptor<TProperty>, 
    StardewUI.Framework.Descriptors.IPropertyDescriptor, 
    StardewUI.Framework.Descriptors.IMemberDescriptor

Type Parameters

TTarget
The property's declaring type.

TProperty
The property value type.

Inheritance
Object ⇦ PrecompiledPropertyDescriptor<TTarget, TProperty>

Implements
IPropertyDescriptor<TProperty>, IPropertyDescriptor, IMemberDescriptor

Members

Constructors

Name Description
PrecompiledPropertyDescriptor<TTarget, TProperty>(string, Boolean, Boolean, Func<TTarget, TProperty>, Action<TTarget, TProperty>) Statically-typed implementation of an IPropertyDescriptor<T> with predefined attributes.

Properties

Name Description
CanRead Whether or not the property is readable, i.e. has a public getter.
CanWrite Whether or not the property is writable, i.e. has a public setter.
DeclaringType The type on which the member is declared.
IsAutoProperty Whether or not the property is likely auto-implemented.
IsField Whether or not the underlying member is a field, rather than a real property.
Name The member name.
ValueType The property's value type.

Methods

Name Description
GetValue(Object) Reads the current property value.
SetValue(Object, TProperty) Writes a new property value.

Details

Constructors

PrecompiledPropertyDescriptor<TTarget, TProperty>(string, bool, bool, Func<TTarget, TProperty>, Action<TTarget, TProperty>)

Statically-typed implementation of an IPropertyDescriptor<T> with predefined attributes.

public PrecompiledPropertyDescriptor<TTarget, TProperty>(string name, bool isField, bool isAutoProperty, Func<TTarget, TProperty> getter, Action<TTarget, TProperty> setter);
Parameters

name   string
The event name.

isField   Boolean
Whether or not this descriptor is really for an unwrapped field.

isAutoProperty   Boolean
Whether or not the property is auto-implemented.

getter   Func<TTarget, TProperty>
Function to retrieve the current property value from a target instance.

setter   Action<TTarget, TProperty>
Function to set the current property value on a target instance.


Properties

CanRead

Whether or not the property is readable, i.e. has a public getter.

public bool CanRead { get; }
Property Value

Boolean


CanWrite

Whether or not the property is writable, i.e. has a public setter.

public bool CanWrite { get; }
Property Value

Boolean


DeclaringType

The type on which the member is declared.

public System.Type DeclaringType { get; }
Property Value

Type


IsAutoProperty

Whether or not the property is likely auto-implemented.

public bool IsAutoProperty { get; }
Property Value

Boolean

Remarks

Auto-property detection is heuristic, relying on the method's IL instructions and the name of its backing field. This can often be interpreted as a signal that the property won't receive property-change notifications, since to do so (whether explicitly or via some weaver/source generator) requires an implementation that is different from the auto-generated getter and setter.

Caveats: This only works as a negative signal (a value of false does not prove that the property will receive notifications, even if the declaring type implements INotifyPropertyChanged), and is somewhat fuzzy even as a negative signal; it is theoretically possible for a source generator or IL weaver to leave behind all the markers of an auto property and still emit notifications, although no known libraries actually do so.


IsField

Whether or not the underlying member is a field, rather than a real property.

public bool IsField { get; }
Property Value

Boolean

Remarks

For binding convenience, fields and properties are both called "properties" for descriptors, as the external access pattern is the same; however, mutable fields can never reliably emit property-change notifications regardless of whether the declaring type implements INotifyPropertyChanged, so this is usually used to emit some warning.


Name

The member name.

public string Name { get; }
Property Value

string


ValueType

The property's value type.

public System.Type ValueType { get; }
Property Value

Type


Methods

GetValue(Object)

Reads the current property value.

public TProperty GetValue(System.Object source);
Parameters

source   Object
An instance of the property's DeclaringType.

Returns

TProperty


SetValue(Object, TProperty)

Writes a new property value.

public void SetValue(System.Object target, TProperty value);
Parameters

target   Object
An instance of the property's DeclaringType.

value   TProperty
The new property value.