/// <summary> /// Initializes a new instance of the <see cref="DirectPropertyBase{TValue}"/> class. /// </summary> /// <param name="source">The property to copy.</param> /// <param name="ownerType">The new owner type.</param> /// <param name="metadata">Optional overridden metadata.</param> protected DirectPropertyBase( DirectPropertyBase <TValue> source, Type ownerType, AvaloniaPropertyMetadata metadata) : base(source, ownerType, metadata) { }
/// <summary> /// Initializes a new instance of the <see cref="AvaloniaProperty"/> class. /// </summary> /// <param name="source">The direct property to copy.</param> /// <param name="ownerType">The new owner type.</param> /// <param name="metadata">Optional overridden metadata.</param> protected AvaloniaProperty( AvaloniaProperty source, Type ownerType, AvaloniaPropertyMetadata metadata) { Contract.Requires <ArgumentNullException>(source != null); Contract.Requires <ArgumentNullException>(ownerType != null); _metadata = new Dictionary <Type, AvaloniaPropertyMetadata>(); Name = source.Name; PropertyType = source.PropertyType; OwnerType = ownerType; Notifying = source.Notifying; Id = source.Id; _defaultMetadata = source._defaultMetadata; // Properties that have different owner can't use fast path for metadata. _hasMetadataOverrides = true; if (metadata != null) { _metadata.Add(ownerType, metadata); } }
/// <summary> /// Initializes a new instance of the <see cref="AvaloniaProperty"/> class. /// </summary> /// <param name="name">The name of the property.</param> /// <param name="valueType">The type of the property's value.</param> /// <param name="ownerType">The type of the class that registers the property.</param> /// <param name="metadata">The property metadata.</param> /// <param name="notifying">A <see cref="Notifying"/> callback.</param> protected AvaloniaProperty( string name, Type valueType, Type ownerType, AvaloniaPropertyMetadata metadata, Action <IAvaloniaObject, bool> notifying = null) { Contract.Requires <ArgumentNullException>(name != null); Contract.Requires <ArgumentNullException>(valueType != null); Contract.Requires <ArgumentNullException>(ownerType != null); Contract.Requires <ArgumentNullException>(metadata != null); if (name.Contains(".")) { throw new ArgumentException("'name' may not contain periods."); } _metadata = new Dictionary <Type, AvaloniaPropertyMetadata>(); Name = name; PropertyType = valueType; OwnerType = ownerType; Notifying = notifying; Id = s_nextId++; _metadata.Add(ownerType, metadata); _defaultMetadata = metadata; }
/// <summary> /// Initializes a new instance of the <see cref="DirectPropertyBase{TValue}"/> class. /// </summary> /// <param name="name">The name of the property.</param> /// <param name="ownerType">The type of the class that registers the property.</param> /// <param name="metadata">The property metadata.</param> protected DirectPropertyBase( string name, Type ownerType, AvaloniaPropertyMetadata metadata) : base(name, ownerType, metadata) { }
protected DirectPropertyBase( AvaloniaProperty source, Type ownerType, AvaloniaPropertyMetadata metadata) : this(source as DirectPropertyBase <TValue> ?? throw new InvalidOperationException(), ownerType, metadata) { }
/// <summary> /// Initializes a new instance of the <see cref="AvaloniaProperty"/> class. /// </summary> /// <param name="name">The name of the property.</param> /// <param name="valueType">The type of the property's value.</param> /// <param name="ownerType">The type of the class that registers the property.</param> /// <param name="metadata">The property metadata.</param> /// <param name="notifying">A <see cref="Notifying"/> callback.</param> protected AvaloniaProperty( string name, Type valueType, Type ownerType, AvaloniaPropertyMetadata metadata, Action <IAvaloniaObject, bool>?notifying = null) { _ = name ?? throw new ArgumentNullException(nameof(name)); if (name.Contains(".")) { throw new ArgumentException("'name' may not contain periods."); } _metadata = new Dictionary <Type, AvaloniaPropertyMetadata>(); Name = name; PropertyType = valueType ?? throw new ArgumentNullException(nameof(valueType)); OwnerType = ownerType ?? throw new ArgumentNullException(nameof(ownerType)); Notifying = notifying; Id = s_nextId++; _metadata.Add(ownerType, metadata ?? throw new ArgumentNullException(nameof(metadata))); _defaultMetadata = metadata; }
/// <summary> /// Initializes a new instance of the <see cref="AvaloniaProperty{TValue}"/> class. /// </summary> /// <param name="source">The property to copy.</param> /// <param name="ownerType">The new owner type.</param> /// <param name="metadata">Optional overridden metadata.</param> protected AvaloniaProperty( AvaloniaProperty <TValue> source, Type ownerType, AvaloniaPropertyMetadata metadata) : base(source, ownerType, metadata) { _changed = source._changed; }
/// <summary> /// Initializes a new instance of the <see cref="AvaloniaProperty{TValue}"/> class. /// </summary> /// <param name="name">The name of the property.</param> /// <param name="ownerType">The type of the class that registers the property.</param> /// <param name="metadata">The property metadata.</param> /// <param name="notifying">A <see cref="AvaloniaProperty.Notifying"/> callback.</param> protected AvaloniaProperty( string name, Type ownerType, AvaloniaPropertyMetadata metadata, Action <IAvaloniaObject, bool> notifying = null) : base(name, typeof(TValue), ownerType, metadata, notifying) { _changed = new Subject <AvaloniaPropertyChangedEventArgs <TValue> >(); }
/// <summary> /// Merges the metadata with the base metadata. /// </summary> /// <param name="baseMetadata">The base metadata to merge.</param> /// <param name="property">The property to which the metadata is being applied.</param> public virtual void Merge( AvaloniaPropertyMetadata baseMetadata, AvaloniaProperty property) { if (_defaultBindingMode == BindingMode.Default) { _defaultBindingMode = baseMetadata.DefaultBindingMode; } }
/// <inheritdoc/> public override void Merge(AvaloniaPropertyMetadata baseMetadata, AvaloniaProperty property) { base.Merge(baseMetadata, property); if (baseMetadata is StyledPropertyMetadata <TValue> src) { if (!_defaultValue.HasValue) { _defaultValue = src.DefaultValue; } if (CoerceValue == null) { CoerceValue = src.CoerceValue; } } }
/// <summary> /// Overrides the metadata for the property on the specified type. /// </summary> /// <param name="type">The type.</param> /// <param name="metadata">The metadata.</param> protected void OverrideMetadata(Type type, AvaloniaPropertyMetadata metadata) { Contract.Requires <ArgumentNullException>(type != null); Contract.Requires <ArgumentNullException>(metadata != null); if (_metadata.ContainsKey(type)) { throw new InvalidOperationException( $"Metadata is already set for {Name} on {type}."); } var baseMetadata = GetMetadata(type); metadata.Merge(baseMetadata, this); _metadata.Add(type, metadata); _metadataCache.Clear(); _hasMetadataOverrides = true; }
/// <inheritdoc/> public override void Merge(AvaloniaPropertyMetadata baseMetadata, AvaloniaProperty property) { base.Merge(baseMetadata, property); var src = baseMetadata as DirectPropertyMetadata <TValue>; if (src != null) { if (UnsetValue == null) { UnsetValue = src.UnsetValue; } if (EnableDataValidation == null) { EnableDataValidation = src.EnableDataValidation; } } }
/// <summary> /// Initializes a new instance of the <see cref="AvaloniaProperty"/> class. /// </summary> /// <param name="source">The direct property to copy.</param> /// <param name="ownerType">The new owner type.</param> /// <param name="metadata">Optional overridden metadata.</param> protected AvaloniaProperty( AvaloniaProperty source, Type ownerType, AvaloniaPropertyMetadata?metadata) { _metadata = new Dictionary <Type, AvaloniaPropertyMetadata>(); Name = source?.Name ?? throw new ArgumentNullException(nameof(source)); PropertyType = source.PropertyType; OwnerType = ownerType ?? throw new ArgumentNullException(nameof(ownerType)); Notifying = source.Notifying; Id = source.Id; _defaultMetadata = source._defaultMetadata; // Properties that have different owner can't use fast path for metadata. _hasMetadataOverrides = true; if (metadata != null) { _metadata.Add(ownerType, metadata); } }