Skip to content

Commit 529c0ba

Browse files
author
Payman Labbaf
committed
Issue 8 - Use explicit cast instead of DelegateAdjuster.
1 parent af44b83 commit 529c0ba

File tree

2 files changed

+1
-20
lines changed

2 files changed

+1
-20
lines changed

SimpleCQRS/FakeBus.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void RegisterHandler<T>(Action<T> handler) where T : Message
1818
_routes.Add(typeof(T), handlers);
1919
}
2020

21-
handlers.Add(DelegateAdjuster.CastArgument<Message, T>(x => handler(x)));
21+
handlers.Add((x => handler((T)x)));
2222
}
2323

2424
public void Send<T>(T command) where T : Command

SimpleCQRS/InfrastructureCrap.DontBotherReadingItsNotImportant.cs

-19
Original file line numberDiff line numberDiff line change
@@ -254,23 +254,4 @@ public static dynamic AsDynamic(this object o)
254254
return PrivateReflectionDynamicObject.WrapObjectIfNeeded(o);
255255
}
256256
}
257-
258-
public class DelegateAdjuster
259-
{
260-
public static Action<BaseT> CastArgument<BaseT, DerivedT>(Expression<Action<DerivedT>> source) where DerivedT : BaseT
261-
{
262-
if (typeof(DerivedT) == typeof(BaseT))
263-
{
264-
return (Action<BaseT>)((Delegate)source.Compile());
265-
266-
}
267-
ParameterExpression sourceParameter = Expression.Parameter(typeof(BaseT), "source");
268-
var result = Expression.Lambda<Action<BaseT>>(
269-
Expression.Invoke(
270-
source,
271-
Expression.Convert(sourceParameter, typeof(DerivedT))),
272-
sourceParameter);
273-
return result.Compile();
274-
}
275-
}
276257
}

0 commit comments

Comments
 (0)