From e81b22b9d244ca4c10aa2db7d1e0df7833eed8f2 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 25 Aug 2017 00:55:06 +0200 Subject: [PATCH] IResourceProvider -> IResourceNode --- src/Avalonia.Controls/Application.cs | 8 ++++---- src/Avalonia.Controls/Control.cs | 6 +++--- src/Avalonia.Controls/IControl.cs | 2 +- .../Controls/{IResourceProvider.cs => IResourceNode.cs} | 4 ++-- .../Controls/ResourceProviderExtensions.cs | 6 +++--- src/Avalonia.Styling/Styling/ISetStyleParent.cs | 2 +- src/Avalonia.Styling/Styling/IStyle.cs | 2 +- src/Avalonia.Styling/Styling/Style.cs | 8 ++++---- src/Avalonia.Styling/Styling/Styles.cs | 6 +++--- .../MarkupExtensions/DynamicResourceExtension.cs | 8 ++++---- .../MarkupExtensions/StaticResourceExtension.cs | 4 ++-- src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs | 8 ++++---- tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs | 2 +- 13 files changed, 33 insertions(+), 33 deletions(-) rename src/Avalonia.Styling/Controls/{IResourceProvider.cs => IResourceNode.cs} (92%) diff --git a/src/Avalonia.Controls/Application.cs b/src/Avalonia.Controls/Application.cs index ce15c0b9e3..5102c9a952 100644 --- a/src/Avalonia.Controls/Application.cs +++ b/src/Avalonia.Controls/Application.cs @@ -29,7 +29,7 @@ namespace Avalonia /// method. /// - Tracks the lifetime of the application. /// - public class Application : IApplicationLifecycle, IGlobalDataTemplates, IGlobalStyles, IStyleRoot, IResourceProvider + public class Application : IApplicationLifecycle, IGlobalDataTemplates, IGlobalStyles, IStyleRoot, IResourceNode { /// /// The application-global data templates. @@ -126,10 +126,10 @@ namespace Avalonia IStyleHost IStyleHost.StylingParent => null; /// - bool IResourceProvider.HasResources => _resources?.Count > 0; + bool IResourceNode.HasResources => _resources?.Count > 0; /// - IResourceProvider IResourceProvider.ResourceParent => null; + IResourceNode IResourceNode.ResourceParent => null; /// /// Initializes the application by loading XAML etc. @@ -159,7 +159,7 @@ namespace Avalonia } /// - bool IResourceProvider.TryGetResource(string key, out object value) + bool IResourceNode.TryGetResource(string key, out object value) { value = null; return (_resources?.TryGetResource(key, out value) ?? false) || diff --git a/src/Avalonia.Controls/Control.cs b/src/Avalonia.Controls/Control.cs index 889edd48f8..a05dccec58 100644 --- a/src/Avalonia.Controls/Control.cs +++ b/src/Avalonia.Controls/Control.cs @@ -390,10 +390,10 @@ namespace Avalonia.Controls IAvaloniaReadOnlyList ILogical.LogicalChildren => LogicalChildren; /// - bool IResourceProvider.HasResources => _resources?.Count > 0 || Styles.HasResources; + bool IResourceNode.HasResources => _resources?.Count > 0 || Styles.HasResources; /// - IResourceProvider IResourceProvider.ResourceParent => ((IStyleHost)this).StylingParent as IResourceProvider; + IResourceNode IResourceNode.ResourceParent => ((IStyleHost)this).StylingParent as IResourceNode; /// IAvaloniaReadOnlyList IStyleable.Classes => Classes; @@ -480,7 +480,7 @@ namespace Avalonia.Controls } /// - bool IResourceProvider.TryGetResource(string key, out object value) + bool IResourceNode.TryGetResource(string key, out object value) { value = null; return (_resources?.TryGetResource(key, out value) ?? false) || diff --git a/src/Avalonia.Controls/IControl.cs b/src/Avalonia.Controls/IControl.cs index 37ad12cf91..a5730bf398 100644 --- a/src/Avalonia.Controls/IControl.cs +++ b/src/Avalonia.Controls/IControl.cs @@ -14,7 +14,7 @@ namespace Avalonia.Controls /// /// Interface for Avalonia controls. /// - public interface IControl : IVisual, ILogical, ILayoutable, IInputElement, INamed, IResourceProvider, IStyleable, IStyleHost + public interface IControl : IVisual, ILogical, ILayoutable, IInputElement, INamed, IResourceNode, IStyleable, IStyleHost { /// /// Occurs when the control has finished initialization. diff --git a/src/Avalonia.Styling/Controls/IResourceProvider.cs b/src/Avalonia.Styling/Controls/IResourceNode.cs similarity index 92% rename from src/Avalonia.Styling/Controls/IResourceProvider.cs rename to src/Avalonia.Styling/Controls/IResourceNode.cs index e133427350..54cf39e3b5 100644 --- a/src/Avalonia.Styling/Controls/IResourceProvider.cs +++ b/src/Avalonia.Styling/Controls/IResourceNode.cs @@ -5,7 +5,7 @@ namespace Avalonia.Controls /// /// Defines an element that can be queried for resources. /// - public interface IResourceProvider + public interface IResourceNode { /// /// Raised when resources in the element are changed. @@ -20,7 +20,7 @@ namespace Avalonia.Controls /// /// Gets the parent resource provider, if any. /// - IResourceProvider ResourceParent { get; } + IResourceNode ResourceParent { get; } /// /// Tries to find a resource within the element. diff --git a/src/Avalonia.Styling/Controls/ResourceProviderExtensions.cs b/src/Avalonia.Styling/Controls/ResourceProviderExtensions.cs index 45e16438d0..c96e8ea7f3 100644 --- a/src/Avalonia.Styling/Controls/ResourceProviderExtensions.cs +++ b/src/Avalonia.Styling/Controls/ResourceProviderExtensions.cs @@ -14,7 +14,7 @@ namespace Avalonia.Controls /// The control. /// The resource key. /// The resource, or if not found. - public static object FindResource(this IResourceProvider control, string key) + public static object FindResource(this IResourceNode control, string key) { Contract.Requires(control != null); Contract.Requires(key != null); @@ -23,7 +23,7 @@ namespace Avalonia.Controls while (current != null) { - if (current is IResourceProvider host) + if (current is IResourceNode host) { if (host.TryGetResource(key, out var value)) { @@ -37,7 +37,7 @@ namespace Avalonia.Controls return AvaloniaProperty.UnsetValue; } - public static IObservable GetResourceObservable(this IResourceProvider target, string key) + public static IObservable GetResourceObservable(this IResourceNode target, string key) { return Observable.FromEventPattern( x => target.ResourcesChanged += x, diff --git a/src/Avalonia.Styling/Styling/ISetStyleParent.cs b/src/Avalonia.Styling/Styling/ISetStyleParent.cs index da5b34798e..9f5855b401 100644 --- a/src/Avalonia.Styling/Styling/ISetStyleParent.cs +++ b/src/Avalonia.Styling/Styling/ISetStyleParent.cs @@ -17,7 +17,7 @@ namespace Avalonia.Styling /// Sets the style parent. /// /// The parent. - void SetParent(IResourceProvider parent); + void SetParent(IResourceNode parent); /// /// Notifies the style that a change has been made to resources that apply to it. diff --git a/src/Avalonia.Styling/Styling/IStyle.cs b/src/Avalonia.Styling/Styling/IStyle.cs index aa8980ddde..5f12763825 100644 --- a/src/Avalonia.Styling/Styling/IStyle.cs +++ b/src/Avalonia.Styling/Styling/IStyle.cs @@ -8,7 +8,7 @@ namespace Avalonia.Styling /// /// Defines the interface for styles. /// - public interface IStyle : IResourceProvider + public interface IStyle : IResourceNode { /// /// Attaches the style to a control if the style's selector matches. diff --git a/src/Avalonia.Styling/Styling/Style.cs b/src/Avalonia.Styling/Styling/Style.cs index 54b53868da..a0d4c8c087 100644 --- a/src/Avalonia.Styling/Styling/Style.cs +++ b/src/Avalonia.Styling/Styling/Style.cs @@ -17,7 +17,7 @@ namespace Avalonia.Styling { private static Dictionary> _applied = new Dictionary>(); - private IResourceProvider _parent; + private IResourceNode _parent; private ResourceDictionary _resources; /// @@ -68,10 +68,10 @@ namespace Avalonia.Styling public IList Setters { get; set; } = new List(); /// - bool IResourceProvider.HasResources => _resources?.Count > 0; + bool IResourceNode.HasResources => _resources?.Count > 0; /// - IResourceProvider IResourceProvider.ResourceParent => _parent; + IResourceNode IResourceNode.ResourceParent => _parent; /// /// Attaches the style to a control if the style's selector matches. @@ -139,7 +139,7 @@ namespace Avalonia.Styling } /// - void ISetStyleParent.SetParent(IResourceProvider parent) + void ISetStyleParent.SetParent(IResourceNode parent) { if (_parent != null && parent != null) { diff --git a/src/Avalonia.Styling/Styling/Styles.cs b/src/Avalonia.Styling/Styling/Styles.cs index 43a542d460..767d5ce463 100644 --- a/src/Avalonia.Styling/Styling/Styles.cs +++ b/src/Avalonia.Styling/Styling/Styles.cs @@ -14,7 +14,7 @@ namespace Avalonia.Styling /// public class Styles : AvaloniaList, IStyle, ISetStyleParent { - private IResourceProvider _parent; + private IResourceNode _parent; private ResourceDictionary _resources; public Styles() @@ -78,7 +78,7 @@ namespace Avalonia.Styling } /// - IResourceProvider IResourceProvider.ResourceParent => _parent; + IResourceNode IResourceNode.ResourceParent => _parent; /// /// Attaches the style to a control if the style's selector matches. @@ -116,7 +116,7 @@ namespace Avalonia.Styling } /// - void ISetStyleParent.SetParent(IResourceProvider parent) + void ISetStyleParent.SetParent(IResourceNode parent) { if (_parent != null && parent != null) { diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs index 7937be60aa..5e421b7e73 100644 --- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs +++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs @@ -15,7 +15,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions { public class DynamicResourceExtension : MarkupExtension, IBinding { - private IResourceProvider _anchor; + private IResourceNode _anchor; public DynamicResourceExtension() { @@ -33,9 +33,9 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions var context = (ITypeDescriptorContext)serviceProvider; var provideTarget = context.GetService(); - if (!(provideTarget.TargetObject is IResourceProvider)) + if (!(provideTarget.TargetObject is IResourceNode)) { - _anchor = GetAnchor(context); + _anchor = GetAnchor(context); } return this; @@ -47,7 +47,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions object anchor, bool enableDataValidation) { - var control = target as IResourceProvider ?? _anchor; + var control = target as IResourceNode ?? _anchor; if (control != null) { diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs index e3cd7b062b..4764677ede 100644 --- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs +++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs @@ -31,7 +31,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions var context = (ITypeDescriptorContext)serviceProvider; var schemaContext = context.GetService()?.SchemaContext; var ambientProvider = context.GetService(); - var resourceProviderType = schemaContext.GetXamlType(typeof(IResourceProvider)); + var resourceProviderType = schemaContext.GetXamlType(typeof(IResourceNode)); var ambientValues = ambientProvider.GetAllAmbientValues(resourceProviderType); // Look upwards though the ambient context for IResourceProviders which might be able @@ -47,7 +47,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions { // We override XamlType.CanAssignTo in BindingXamlType so the results we get back // from GetAllAmbientValues aren't necessarily of the correct type. - if (ambientValue is IResourceProvider resourceProvider) + if (ambientValue is IResourceNode resourceProvider) { if (resourceProvider is IControl control && control.StylingParent != null) { diff --git a/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs b/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs index a121cd8c1b..c1867da9c0 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs +++ b/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs @@ -14,7 +14,7 @@ namespace Avalonia.Markup.Xaml.Styling { private Uri _baseUri; private IStyle _loaded; - private IResourceProvider _parent; + private IResourceNode _parent; /// /// Initializes a new instance of the class. @@ -52,10 +52,10 @@ namespace Avalonia.Markup.Xaml.Styling } /// - bool IResourceProvider.HasResources => Loaded.HasResources; + bool IResourceNode.HasResources => Loaded.HasResources; /// - IResourceProvider IResourceProvider.ResourceParent => _parent; + IResourceNode IResourceNode.ResourceParent => _parent; /// public void Attach(IStyleable control, IStyleHost container) @@ -76,7 +76,7 @@ namespace Avalonia.Markup.Xaml.Styling } /// - void ISetStyleParent.SetParent(IResourceProvider parent) + void ISetStyleParent.SetParent(IResourceNode parent) { if (_parent != null && parent != null) { diff --git a/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs b/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs index 8bf6102f27..98aaa29261 100644 --- a/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs +++ b/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs @@ -162,7 +162,7 @@ namespace Avalonia.Layout.UnitTests private void RegisterServices() { var globalStyles = new Mock(); - var globalStylesResources = globalStyles.As(); + var globalStylesResources = globalStyles.As(); var outObj = (object)10; globalStylesResources.Setup(x => x.TryGetResource("FontSizeNormal", out outObj)).Returns(true);