Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

VerbExecutionContext base class

  • Loading branch information...
commit c8a92351d566f60747845e682e599929fac78ded 1 parent ffcb828
@adrianaisemberg adrianaisemberg authored
View
1  CLAP/CLAP.csproj
@@ -84,6 +84,7 @@
<Compile Include="Interception\IVerbExecutionContext.cs" />
<Compile Include="Interception\PreVerbExecutionAttribute.cs" />
<Compile Include="Interception\PreVerbExecutionContext.cs" />
+ <Compile Include="Interception\VerbExecutionContext.cs" />
<Compile Include="Method.cs" />
<Compile Include="Parameter.cs" />
<Compile Include="ParameterAttribute.cs" />
View
17 CLAP/Interception/PostVerbExecutionContext.cs
@@ -3,14 +3,10 @@
namespace CLAP.Interception
{
- public sealed class PostVerbExecutionContext : IVerbExecutionContext
+ public sealed class PostVerbExecutionContext : VerbExecutionContext, IVerbExecutionContext
{
#region Properties
- public Method Method { get; private set; }
- public object Target { get; private set; }
- public ParameterAndValue[] Parameters { get; private set; }
-
public bool Cancelled { get; private set; }
public Exception Exception { get; private set; }
@@ -19,8 +15,6 @@ public bool Failed
get { return Exception != null; }
}
- public Dictionary<object, object> UserContext { get; private set; }
-
#endregion Properties
#region Constructors
@@ -30,15 +24,12 @@ public bool Failed
object target,
ParameterAndValue[] parameters,
bool cancelled,
- Exception ex,
+ Exception exception,
Dictionary<object, object> userContext)
+ : base(method, target, parameters, userContext)
{
- Method = method;
- Target = target;
- Parameters = parameters;
Cancelled = cancelled;
- Exception = ex;
- UserContext = userContext;
+ Exception = exception;
}
#endregion Constructors
View
14 CLAP/Interception/PreVerbExecutionContext.cs
@@ -2,18 +2,12 @@
namespace CLAP.Interception
{
- public sealed class PreVerbExecutionContext : IVerbExecutionContext
+ public sealed class PreVerbExecutionContext : VerbExecutionContext, IVerbExecutionContext
{
#region Properties
- public Method Method { get; private set; }
- public object Target { get; private set; }
- public ParameterAndValue[] Parameters { get; private set; }
-
public bool Cancel { get; set; }
- public Dictionary<object, object> UserContext { get; set; }
-
#endregion Properties
#region Constructors
@@ -22,12 +16,8 @@ public sealed class PreVerbExecutionContext : IVerbExecutionContext
Method method,
object target,
ParameterAndValue[] parameters)
+ : base(method, target, parameters, new Dictionary<object, object>())
{
- Method = method;
- Target = target;
- Parameters = parameters;
-
- UserContext = new Dictionary<object, object>();
}
#endregion Constructors
View
24 CLAP/Interception/VerbExecutionContext.cs
@@ -0,0 +1,24 @@
+using System.Collections.Generic;
+
+namespace CLAP.Interception
+{
+ public abstract class VerbExecutionContext
+ {
+ public Method Method { get; private set; }
+ public object Target { get; private set; }
+ public ParameterAndValue[] Parameters { get; private set; }
+ public Dictionary<object, object> UserContext { get; private set; }
+
+ protected VerbExecutionContext(
+ Method method,
+ object target,
+ ParameterAndValue[] parameters,
+ Dictionary<object, object> userContext)
+ {
+ Method = method;
+ Target = target;
+ Parameters = parameters;
+ UserContext = userContext;
+ }
+ }
+}
View
2  Tests/Samples.cs
@@ -798,6 +798,8 @@ public void Foo(string str, int num)
private void Pre(PreVerbExecutionContext context)
{
PreContext = context;
+
+ context.UserContext.Add("a", 54);
}
[PostVerbExecution]
View
2  Tests/Tests.cs
@@ -1915,6 +1915,8 @@ public void Interception_PreAndPostExecuted_VerbExecuted()
Assert.AreEqual("blah", s.PostContext.Parameters.First(p => p.Parameter.ParameterInfo.Name == "str").Value);
Assert.AreEqual(554, s.PostContext.Parameters.First(p => p.Parameter.ParameterInfo.Name == "num").Value);
+ Assert.AreEqual(54, s.PostContext.UserContext["a"]);
+
Assert.IsTrue(s.VerbExecuted);
}
Please sign in to comment.
Something went wrong with that request. Please try again.