diff --git a/src/Umbraco.Core/Events/CancellableEventArgs.cs b/src/Umbraco.Core/Events/CancellableEventArgs.cs index a245aeb367..7a10623427 100644 --- a/src/Umbraco.Core/Events/CancellableEventArgs.cs +++ b/src/Umbraco.Core/Events/CancellableEventArgs.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Security.Permissions; -using Umbraco.Core.Models.PublishedContent; namespace Umbraco.Core.Events { @@ -13,13 +12,15 @@ namespace Umbraco.Core.Events public class CancellableEventArgs : EventArgs, IEquatable { private bool _cancel; + private Dictionary _eventState; + + private static readonly ReadOnlyDictionary EmptyAdditionalData = new ReadOnlyDictionary(new Dictionary()); public CancellableEventArgs(bool canCancel, EventMessages messages, IDictionary additionalData) { CanCancel = canCancel; Messages = messages; AdditionalData = new ReadOnlyDictionary(additionalData); - EventState = new Dictionary(); } public CancellableEventArgs(bool canCancel, EventMessages eventMessages) @@ -27,8 +28,7 @@ namespace Umbraco.Core.Events if (eventMessages == null) throw new ArgumentNullException("eventMessages"); CanCancel = canCancel; Messages = eventMessages; - AdditionalData = new ReadOnlyDictionary(new Dictionary()); - EventState = new Dictionary(); + AdditionalData = EmptyAdditionalData; } public CancellableEventArgs(bool canCancel) @@ -36,19 +36,16 @@ namespace Umbraco.Core.Events CanCancel = canCancel; //create a standalone messages Messages = new EventMessages(); - AdditionalData = new ReadOnlyDictionary(new Dictionary()); - EventState = new Dictionary(); + AdditionalData = EmptyAdditionalData; } public CancellableEventArgs(EventMessages eventMessages) : this(true, eventMessages) - { - } + { } public CancellableEventArgs() : this(true) - { - } + { } /// /// Flag to determine if this instance will support being cancellable @@ -98,16 +95,19 @@ namespace Umbraco.Core.Events /// In some cases raised evens might need to contain additional arbitrary readonly data which can be read by event subscribers /// /// - /// This allows for a bit of flexibility in our event raising - it's not pretty but we need to maintain backwards compatibility + /// This allows for a bit of flexibility in our event raising - it's not pretty but we need to maintain backwards compatibility /// so we cannot change the strongly typed nature for some events. /// public ReadOnlyDictionary AdditionalData { get; private set; } /// - /// This can be used by event subscribers to store state in the event args so they easily deal with custom state data between a starting ("ing") + /// This can be used by event subscribers to store state in the event args so they easily deal with custom state data between a starting ("ing") /// event and an ending ("ed") event - /// - public IDictionary EventState { get; private set; } + /// + public IDictionary EventState + { + get { return _eventState ?? (_eventState = new Dictionary()); } + } public bool Equals(CancellableEventArgs other) { @@ -120,13 +120,13 @@ namespace Umbraco.Core.Events { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; + if (obj.GetType() != GetType()) return false; return Equals((CancellableEventArgs) obj); } public override int GetHashCode() { - return (AdditionalData != null ? AdditionalData.GetHashCode() : 0); + return AdditionalData != null ? AdditionalData.GetHashCode() : 0; } public static bool operator ==(CancellableEventArgs left, CancellableEventArgs right) @@ -136,7 +136,7 @@ namespace Umbraco.Core.Events public static bool operator !=(CancellableEventArgs left, CancellableEventArgs right) { - return !Equals(left, right); + return Equals(left, right) == false; } } } \ No newline at end of file