Browse Source

Added ResourcesChangedEventArgs.Empty.

We don't need to allocate a new instance each time.
pull/3957/head
Steven Kirk 6 years ago
parent
commit
0a1cb6fdf8
  1. 2
      src/Avalonia.Controls/Application.cs
  2. 6
      src/Avalonia.Styling/Controls/ResourceDictionary.cs
  3. 1
      src/Avalonia.Styling/Controls/ResourcesChangedEventArgs.cs
  4. 6
      src/Avalonia.Styling/StyledElement.cs
  5. 2
      src/Avalonia.Styling/Styling/Style.cs

2
src/Avalonia.Controls/Application.cs

@ -260,7 +260,7 @@ namespace Avalonia
try try
{ {
_notifyingResourcesChanged = true; _notifyingResourcesChanged = true;
ResourcesChanged?.Invoke(this, new ResourcesChangedEventArgs()); ResourcesChanged?.Invoke(this, ResourcesChangedEventArgs.Empty);
} }
finally finally
{ {

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

@ -146,7 +146,7 @@ namespace Avalonia.Controls
if (hasResources) if (hasResources)
{ {
owner.NotifyHostedResourcesChanged(new ResourcesChangedEventArgs()); owner.NotifyHostedResourcesChanged(ResourcesChangedEventArgs.Empty);
} }
} }
@ -171,14 +171,14 @@ namespace Avalonia.Controls
if (hasResources) if (hasResources)
{ {
owner.NotifyHostedResourcesChanged(new ResourcesChangedEventArgs()); owner.NotifyHostedResourcesChanged(ResourcesChangedEventArgs.Empty);
} }
} }
} }
private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{ {
Owner?.NotifyHostedResourcesChanged(new ResourcesChangedEventArgs()); Owner?.NotifyHostedResourcesChanged(ResourcesChangedEventArgs.Empty);
} }
} }
} }

1
src/Avalonia.Styling/Controls/ResourcesChangedEventArgs.cs

@ -4,5 +4,6 @@ namespace Avalonia.Controls
{ {
public class ResourcesChangedEventArgs : EventArgs public class ResourcesChangedEventArgs : EventArgs
{ {
public static new readonly ResourcesChangedEventArgs Empty = new ResourcesChangedEventArgs();
} }
} }

6
src/Avalonia.Styling/StyledElement.cs

@ -509,7 +509,7 @@ namespace Avalonia
if (count > 0) if (count > 0)
{ {
e ??= new ResourcesChangedEventArgs(); e ??= ResourcesChangedEventArgs.Empty;
for (var i = 0; i < count; ++i) for (var i = 0; i < count; ++i)
{ {
@ -803,13 +803,13 @@ namespace Avalonia
{ {
if (ResourcesChanged is object) if (ResourcesChanged is object)
{ {
e ??= new ResourcesChangedEventArgs(); e ??= ResourcesChangedEventArgs.Empty;
ResourcesChanged(this, e); ResourcesChanged(this, e);
} }
if (propagate) if (propagate)
{ {
e ??= new ResourcesChangedEventArgs(); e ??= ResourcesChangedEventArgs.Empty;
NotifyChildResourcesChanged(e); NotifyChildResourcesChanged(e);
} }
} }

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

@ -67,7 +67,7 @@ namespace Avalonia.Styling
if (hadResources || _resources.HasResources) if (hadResources || _resources.HasResources)
{ {
Owner.NotifyHostedResourcesChanged(new ResourcesChangedEventArgs()); Owner.NotifyHostedResourcesChanged(ResourcesChangedEventArgs.Empty);
} }
} }
} }

Loading…
Cancel
Save