From 8c9d610438847b092f4072e21a6fc6d4d859aa67 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 15 May 2023 17:30:42 +0200 Subject: [PATCH] Make some AvaloniaProperty APIs internal. - Constructors are now internal: properties should only be created using the `Register*` methods anyway - `Notifying` is now internal, this should only be needed by `DataContext` and the constructor which set this was already made internal - Base `OverrideMetadata` methods are now internal: the implementations on `StyledProperty` should be used --- src/Avalonia.Base/AttachedProperty.cs | 2 +- src/Avalonia.Base/AvaloniaProperty.cs | 10 +++--- src/Avalonia.Base/AvaloniaProperty`1.cs | 8 ++--- src/Avalonia.Base/DirectProperty.cs | 41 +------------------------ src/Avalonia.Base/DirectPropertyBase.cs | 4 +-- src/Avalonia.Base/StyledProperty.cs | 2 +- 6 files changed, 14 insertions(+), 53 deletions(-) diff --git a/src/Avalonia.Base/AttachedProperty.cs b/src/Avalonia.Base/AttachedProperty.cs index 27844023ae..6269df2a26 100644 --- a/src/Avalonia.Base/AttachedProperty.cs +++ b/src/Avalonia.Base/AttachedProperty.cs @@ -17,7 +17,7 @@ namespace Avalonia /// The property metadata. /// Whether the property inherits its value. /// A value validation callback. - public AttachedProperty( + internal AttachedProperty( string name, Type ownerType, Type hostType, diff --git a/src/Avalonia.Base/AvaloniaProperty.cs b/src/Avalonia.Base/AvaloniaProperty.cs index 332ca1802c..95f8eea852 100644 --- a/src/Avalonia.Base/AvaloniaProperty.cs +++ b/src/Avalonia.Base/AvaloniaProperty.cs @@ -42,7 +42,7 @@ namespace Avalonia /// The class that the property being is registered on. /// The property metadata. /// A callback. - protected AvaloniaProperty( + private protected AvaloniaProperty( string name, Type valueType, Type ownerType, @@ -76,7 +76,7 @@ namespace Avalonia /// The direct property to copy. /// The new owner type. /// Optional overridden metadata. - protected AvaloniaProperty( + private protected AvaloniaProperty( AvaloniaProperty source, Type ownerType, AvaloniaPropertyMetadata? metadata) @@ -153,7 +153,7 @@ namespace Avalonia /// will be true before the property change notifications are sent and false afterwards. This /// callback is intended to support Control.IsDataContextChanging. /// - public Action? Notifying { get; } + internal Action? Notifying { get; } /// /// Gets the integer ID that represents this property. @@ -558,7 +558,7 @@ namespace Avalonia /// /// The type. /// The metadata. - protected void OverrideMetadata(Type type, AvaloniaPropertyMetadata metadata) + private protected void OverrideMetadata(Type type, AvaloniaPropertyMetadata metadata) { _ = type ?? throw new ArgumentNullException(nameof(type)); _ = metadata ?? throw new ArgumentNullException(nameof(metadata)); @@ -577,7 +577,7 @@ namespace Avalonia _singleMetadata = null; } - protected abstract IObservable GetChanged(); + private protected abstract IObservable GetChanged(); private AvaloniaPropertyMetadata GetMetadataWithOverrides(Type type) { diff --git a/src/Avalonia.Base/AvaloniaProperty`1.cs b/src/Avalonia.Base/AvaloniaProperty`1.cs index f08c0e0a02..ea2f3577e5 100644 --- a/src/Avalonia.Base/AvaloniaProperty`1.cs +++ b/src/Avalonia.Base/AvaloniaProperty`1.cs @@ -22,7 +22,7 @@ namespace Avalonia /// The class that the property being is registered on. /// The property metadata. /// A callback. - protected AvaloniaProperty( + private protected AvaloniaProperty( string name, Type ownerType, Type hostType, @@ -39,7 +39,7 @@ namespace Avalonia /// The property to copy. /// The new owner type. /// Optional overridden metadata. - protected AvaloniaProperty( + private protected AvaloniaProperty( AvaloniaProperty source, Type ownerType, AvaloniaPropertyMetadata? metadata) @@ -68,10 +68,10 @@ namespace Avalonia _changed.OnNext(e); } - protected override IObservable GetChanged() => Changed; + private protected override IObservable GetChanged() => Changed; [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = TrimmingMessages.ImplicitTypeConvertionSupressWarningMessage)] - protected BindingValue TryConvert(object? value) + private protected BindingValue TryConvert(object? value) { if (value == UnsetValue) { diff --git a/src/Avalonia.Base/DirectProperty.cs b/src/Avalonia.Base/DirectProperty.cs index d02e277074..dd02553eaf 100644 --- a/src/Avalonia.Base/DirectProperty.cs +++ b/src/Avalonia.Base/DirectProperty.cs @@ -24,7 +24,7 @@ namespace Avalonia /// Gets the current value of the property. /// Sets the value of the property. May be null. /// The property metadata. - public DirectProperty( + internal DirectProperty( string name, Func getter, Action? setter, @@ -106,45 +106,6 @@ namespace Avalonia return result; } - /// - /// Registers the direct property on another type. - /// - /// The type of the additional owner. - /// Gets the current value of the property. - /// Sets the value of the property. - /// - /// The value to use when the property is set to - /// - /// The default binding mode for the property. - /// - /// Whether the property is interested in data validation. - /// - /// The property. - public DirectProperty AddOwnerWithDataValidation( - Func getter, - Action setter, - TValue unsetValue = default!, - BindingMode defaultBindingMode = BindingMode.Default, - bool enableDataValidation = false) - where TNewOwner : AvaloniaObject - { - var metadata = new DirectPropertyMetadata( - unsetValue: unsetValue, - defaultBindingMode: defaultBindingMode, - enableDataValidation: enableDataValidation); - - metadata.Merge(GetMetadata(), this); - - var result = new DirectProperty( - this, - getter, - setter, - metadata); - - AvaloniaPropertyRegistry.Instance.Register(typeof(TNewOwner), result); - return result; - } - /// internal override TValue InvokeGetter(AvaloniaObject instance) { diff --git a/src/Avalonia.Base/DirectPropertyBase.cs b/src/Avalonia.Base/DirectPropertyBase.cs index 94694e6209..4dddc12794 100644 --- a/src/Avalonia.Base/DirectPropertyBase.cs +++ b/src/Avalonia.Base/DirectPropertyBase.cs @@ -20,7 +20,7 @@ namespace Avalonia /// The name of the property. /// The type of the class that registers the property. /// The property metadata. - protected DirectPropertyBase( + private protected DirectPropertyBase( string name, Type ownerType, AvaloniaPropertyMetadata metadata) @@ -35,7 +35,7 @@ namespace Avalonia /// The property to copy. /// The new owner type. /// Optional overridden metadata. - protected DirectPropertyBase( + private protected DirectPropertyBase( DirectPropertyBase source, Type ownerType, AvaloniaPropertyMetadata metadata) diff --git a/src/Avalonia.Base/StyledProperty.cs b/src/Avalonia.Base/StyledProperty.cs index 76ba83b88d..ee8748956e 100644 --- a/src/Avalonia.Base/StyledProperty.cs +++ b/src/Avalonia.Base/StyledProperty.cs @@ -24,7 +24,7 @@ namespace Avalonia /// This method is not part of the property's metadata and so cannot be changed after registration. /// /// A callback. - public StyledProperty( + internal StyledProperty( string name, Type ownerType, Type hostType,