Browse Source

Use object for resource keys.

`IResourceDictionary` was defined as an `IDictionary<object, object>` but in various places we only accepted a `string` as the resource key. Fix this inconsistency and always use `object` as a resource key.

Fixes #2456
pull/2541/head
Steven Kirk 7 years ago
parent
commit
0f25e0548f
  1. 2
      src/Avalonia.Controls/Application.cs
  2. 2
      src/Avalonia.Styling/Controls/IResourceProvider.cs
  3. 2
      src/Avalonia.Styling/Controls/ResourceDictionary.cs
  4. 10
      src/Avalonia.Styling/Controls/ResourceProviderExtensions.cs
  5. 2
      src/Avalonia.Styling/StyledElement.cs
  6. 2
      src/Avalonia.Styling/Styling/Style.cs
  7. 2
      src/Avalonia.Styling/Styling/Styles.cs
  8. 2
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs
  9. 2
      src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs
  10. 2
      src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs

2
src/Avalonia.Controls/Application.cs

@ -362,7 +362,7 @@ namespace Avalonia
} }
/// <inheritdoc/> /// <inheritdoc/>
bool IResourceProvider.TryGetResource(string key, out object value) bool IResourceProvider.TryGetResource(object key, out object value)
{ {
value = null; value = null;
return (_resources?.TryGetResource(key, out value) ?? false) || return (_resources?.TryGetResource(key, out value) ?? false) ||

2
src/Avalonia.Styling/Controls/IResourceProvider.cs

@ -28,6 +28,6 @@ namespace Avalonia.Controls
/// <returns> /// <returns>
/// True if the resource if found, otherwise false. /// True if the resource if found, otherwise false.
/// </returns> /// </returns>
bool TryGetResource(string key, out object value); bool TryGetResource(object key, out object value);
} }
} }

2
src/Avalonia.Styling/Controls/ResourceDictionary.cs

@ -69,7 +69,7 @@ namespace Avalonia.Controls
} }
/// <inheritdoc/> /// <inheritdoc/>
public bool TryGetResource(string key, out object value) public bool TryGetResource(object key, out object value)
{ {
if (TryGetValue(key, out value)) if (TryGetValue(key, out value))
{ {

10
src/Avalonia.Styling/Controls/ResourceProviderExtensions.cs

@ -11,7 +11,7 @@ namespace Avalonia.Controls
/// <param name="control">The control.</param> /// <param name="control">The control.</param>
/// <param name="key">The resource key.</param> /// <param name="key">The resource key.</param>
/// <returns>The resource, or <see cref="AvaloniaProperty.UnsetValue"/> if not found.</returns> /// <returns>The resource, or <see cref="AvaloniaProperty.UnsetValue"/> if not found.</returns>
public static object FindResource(this IResourceNode control, string key) public static object FindResource(this IResourceNode control, object key)
{ {
if (control.TryFindResource(key, out var value)) if (control.TryFindResource(key, out var value))
{ {
@ -28,7 +28,7 @@ namespace Avalonia.Controls
/// <param name="key">The resource key.</param> /// <param name="key">The resource key.</param>
/// <param name="value">On return, contains the resource if found, otherwise null.</param> /// <param name="value">On return, contains the resource if found, otherwise null.</param>
/// <returns>True if the resource was found; otherwise false.</returns> /// <returns>True if the resource was found; otherwise false.</returns>
public static bool TryFindResource(this IResourceNode control, string key, out object value) public static bool TryFindResource(this IResourceNode control, object key, out object value)
{ {
Contract.Requires<ArgumentNullException>(control != null); Contract.Requires<ArgumentNullException>(control != null);
Contract.Requires<ArgumentNullException>(key != null); Contract.Requires<ArgumentNullException>(key != null);
@ -52,7 +52,7 @@ namespace Avalonia.Controls
return false; return false;
} }
public static IObservable<object> GetResourceObservable(this IResourceNode target, string key) public static IObservable<object> GetResourceObservable(this IResourceNode target, object key)
{ {
return new ResourceObservable(target, key); return new ResourceObservable(target, key);
} }
@ -60,9 +60,9 @@ namespace Avalonia.Controls
private class ResourceObservable : LightweightObservableBase<object> private class ResourceObservable : LightweightObservableBase<object>
{ {
private readonly IResourceNode _target; private readonly IResourceNode _target;
private readonly string _key; private readonly object _key;
public ResourceObservable(IResourceNode target, string key) public ResourceObservable(IResourceNode target, object key)
{ {
_target = target; _target = target;
_key = key; _key = key;

2
src/Avalonia.Styling/StyledElement.cs

@ -415,7 +415,7 @@ namespace Avalonia
} }
/// <inheritdoc/> /// <inheritdoc/>
bool IResourceProvider.TryGetResource(string key, out object value) bool IResourceProvider.TryGetResource(object key, out object value)
{ {
value = null; value = null;
return (_resources?.TryGetResource(key, out value) ?? false) || return (_resources?.TryGetResource(key, out value) ?? false) ||

2
src/Avalonia.Styling/Styling/Style.cs

@ -171,7 +171,7 @@ namespace Avalonia.Styling
} }
/// <inheritdoc/> /// <inheritdoc/>
public bool TryGetResource(string key, out object result) public bool TryGetResource(object key, out object result)
{ {
result = null; result = null;
return _resources?.TryGetResource(key, out result) ?? false; return _resources?.TryGetResource(key, out result) ?? false;

2
src/Avalonia.Styling/Styling/Styles.cs

@ -178,7 +178,7 @@ namespace Avalonia.Styling
} }
/// <inheritdoc/> /// <inheritdoc/>
public bool TryGetResource(string key, out object value) public bool TryGetResource(object key, out object value)
{ {
if (_resources != null && _resources.TryGetValue(key, out value)) if (_resources != null && _resources.TryGetValue(key, out value))
{ {

2
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/DynamicResourceExtension.cs

@ -26,7 +26,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
ResourceKey = resourceKey; ResourceKey = resourceKey;
} }
public string ResourceKey { get; set; } public object ResourceKey { get; set; }
public override object ProvideValue(IServiceProvider serviceProvider) => ProvideTypedValue(serviceProvider); public override object ProvideValue(IServiceProvider serviceProvider) => ProvideTypedValue(serviceProvider);

2
src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/ResourceInclude.cs

@ -47,7 +47,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
bool IResourceProvider.HasResources => Loaded.HasResources; bool IResourceProvider.HasResources => Loaded.HasResources;
/// <inhertidoc/> /// <inhertidoc/>
bool IResourceProvider.TryGetResource(string key, out object value) bool IResourceProvider.TryGetResource(object key, out object value)
{ {
return Loaded.TryGetResource(key, out value); return Loaded.TryGetResource(key, out value);
} }

2
src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs

@ -86,7 +86,7 @@ namespace Avalonia.Markup.Xaml.Styling
} }
/// <inheritdoc/> /// <inheritdoc/>
public bool TryGetResource(string key, out object value) => Loaded.TryGetResource(key, out value); public bool TryGetResource(object key, out object value) => Loaded.TryGetResource(key, out value);
/// <inheritdoc/> /// <inheritdoc/>
void ISetStyleParent.NotifyResourcesChanged(ResourcesChangedEventArgs e) void ISetStyleParent.NotifyResourcesChanged(ResourcesChangedEventArgs e)

Loading…
Cancel
Save