Removed ICancellableObjectEventArgs and instead just have a base class without the strongly typed object...

CancellableEventArgs.
This commit is contained in:
Shannon Deminick
2012-12-15 21:41:09 +05:00
parent b144e27d10
commit 94f69d5007
5 changed files with 55 additions and 51 deletions

View File

@@ -0,0 +1,51 @@
using System;
using System.Security.Permissions;
namespace Umbraco.Core.Events
{
/// <summary>
/// Event args for that can support cancellation
/// </summary>
[HostProtection(SecurityAction.LinkDemand, SharedState = true)]
public class CancellableEventArgs : EventArgs
{
private bool _cancel;
public CancellableEventArgs(bool canCancel)
{
CanCancel = canCancel;
}
public CancellableEventArgs()
: this(true)
{
}
/// <summary>
/// Flag to determine if this instance will support being cancellable
/// </summary>
public bool CanCancel { get; set; }
/// <summary>
/// If this instance supports cancellation, this gets/sets the cancel value
/// </summary>
public bool Cancel
{
get
{
if (!CanCancel)
{
throw new InvalidOperationException("This event argument class does not support cancelling.");
}
return _cancel;
}
set
{
if (!CanCancel)
{
throw new InvalidOperationException("This event argument class does not support cancelling.");
}
_cancel = value;
}
}
}
}

View File

@@ -1,4 +1,3 @@
using System;
using System.Security.Permissions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
@@ -10,14 +9,13 @@ namespace Umbraco.Core.Events
/// </summary>
/// <typeparam name="T"></typeparam>
[HostProtection(SecurityAction.LinkDemand, SharedState = true)]
public class CancellableObjectEventArgs<T> : EventArgs, ICancellableObjectEventArgs
public class CancellableObjectEventArgs<T> : CancellableEventArgs
{
private bool _cancel;
public CancellableObjectEventArgs(T entity, bool canCancel)
: base(canCancel)
{
Entity = entity;
CanCancel = canCancel;
}
public CancellableObjectEventArgs(T entity)
@@ -25,33 +23,6 @@ namespace Umbraco.Core.Events
{
}
/// <summary>
/// Flag to determine if this instance will support being cancellable
/// </summary>
public bool CanCancel { get; set; }
/// <summary>
/// If this instance supports cancellation, this gets/sets the cancel value
/// </summary>
public bool Cancel
{
get
{
if (!CanCancel)
{
throw new InvalidOperationException("This event argument class does not support cancelling.");
}
return _cancel;
}
set
{
if (!CanCancel)
{
throw new InvalidOperationException("This event argument class does not support cancelling.");
}
_cancel = value;
}
}
public T Entity { get; private set; }

View File

@@ -20,7 +20,7 @@ namespace Umbraco.Core.Events
this TypedEventHandler<TSender, TArgs> eventHandler,
TArgs args,
TSender sender)
where TArgs : ICancellableObjectEventArgs
where TArgs : CancellableEventArgs
{
if (eventHandler != null)
eventHandler(sender, args);

View File

@@ -1,18 +0,0 @@
namespace Umbraco.Core.Events
{
/// <summary>
/// Interface for EventArgs clases to implement when they support cancelling operations
/// </summary>
public interface ICancellableObjectEventArgs
{
/// <summary>
/// If this instance supports cancellation, this gets/sets the cancel value
/// </summary>
bool Cancel { get; set; }
/// <summary>
/// Flag to determine if this instance will support being cancellable
/// </summary>
bool CanCancel { get; set; }
}
}

View File

@@ -117,12 +117,12 @@
<Compile Include="Dictionary\CultureDictionaryFactoryResolver.cs" />
<Compile Include="Dictionary\ICultureDictionaryFactory.cs" />
<Compile Include="Dynamics\DynamicInstanceHelper.cs" />
<Compile Include="Events\CancellableEventArgs.cs" />
<Compile Include="Events\ContentCacheEventArgs.cs" />
<Compile Include="Events\CopyEventArgs.cs" />
<Compile Include="Events\DeleteEventArgs.cs" />
<Compile Include="Events\CancellableObjectEventArgs.cs" />
<Compile Include="Events\EventExtensions.cs" />
<Compile Include="Events\ICancellableObjectEventArgs.cs" />
<Compile Include="Events\TypedEventHandler.cs" />
<Compile Include="Events\PublishingEventArgs.cs" />
<Compile Include="Events\MoveEventArgs.cs" />