Permalink
Browse files

Allowed value types as event data

  • Loading branch information...
1 parent 0e7b98b commit e047d354dd199016e84229e4acfce5f24cd210cc @bytenik bytenik committed May 31, 2012
@@ -18,7 +18,6 @@ namespace Magnum.StateMachine
public class DataEventAction<T, TData> :
EventActionBase<T>
where T : StateMachine<T>
- where TData : class
{
private Func<TData, bool> _checkCondition = x => true;
@@ -80,7 +79,9 @@ public DataEventAction(Event definedEvent)
protected override bool ParameterMeetsCondition(object parameter)
{
- var eventData = parameter as TData;
+ if (!(parameter is TData))
+ return false;
+ var eventData = (TData) parameter;
if (eventData == null)
return false;
@@ -47,7 +47,6 @@ public void Add(Action<T> action, params ExceptionAction<T>[] exceptionActions)
}
public void Add<TData>(Action<T, TData> action, params ExceptionAction<T>[] exceptionActions)
- where TData : class
{
_actions.Add(new ActionItem
{
@@ -57,7 +56,6 @@ public void Add<TData>(Action<T, TData> action, params ExceptionAction<T>[] exce
}
public void Add<TData>(Action<T, DataEvent<T, TData>, TData> action, params ExceptionAction<T>[] exceptionActions)
- where TData : class
{
_actions.Add(new ActionItem
{
@@ -76,7 +74,6 @@ public void Add(Expression<Action<T>> expression, params ExceptionAction<T>[] ex
}
public void Add<TData>(Expression<Action<T, TData>> expression, params ExceptionAction<T>[] exceptionActions)
- where TData : class
{
_actions.Add(new ActionItem
{
@@ -39,7 +39,6 @@ public void Execute(T instance, Event @event, object parameter)
public class ExpressionAction<T, TData> :
EventAction<T>
where T : StateMachine<T>
- where TData : class
{
private readonly Action<T, TData> _action;
@@ -53,7 +52,7 @@ public ExpressionAction(Expression<Action<T, TData>> expression)
public void Execute(T instance, Event @event, object parameter)
{
- _action(instance, parameter as TData);
+ _action(instance, (parameter is TData) ? ((TData)parameter) : default(TData));
}
}
}
@@ -34,7 +34,6 @@ public void Execute(T instance, Event @event, object parameter)
public class LambdaAction<T, TData> :
EventAction<T>
where T : StateMachine<T>
- where TData : class
{
private readonly Action<T, DataEvent<T, TData>, TData> _action;
@@ -45,7 +44,7 @@ public LambdaAction(Action<T, DataEvent<T, TData>, TData> action)
public void Execute(T instance, Event @event, object parameter)
{
- _action(instance, @event as DataEvent<T, TData>, parameter as TData);
+ _action(instance, @event as DataEvent<T, TData>, (parameter is TData) ? ((TData) parameter) : default(TData));
}
}
}
@@ -194,7 +194,6 @@ protected static BasicEventAction<T> When(Event raised)
/// </summary>
/// <param name="raised">The event that would be raised</param>
protected static DataEventAction<T, TData> When<TData>(Event<TData> raised)
- where TData : class
{
DataEvent<T, TData> eevent = DataEvent<T, TData>.GetEvent(raised);

0 comments on commit e047d35

Please sign in to comment.