Skip to content

Commit

Permalink
Added an example related to work with MethodInterceptionAspect.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Jun 24, 2013
1 parent 6f63118 commit 99574e4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/VS 2010/KingAOP.Examples/HelloWorld/HelloWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ public void HelloWorldCall()
{
Console.WriteLine("Hello World");
}

[NotNullInvocationAspect]
public void PrintIfArgNotNull(string text)
{
Console.WriteLine("\n" + "PrintIfArgNotNull");
Console.WriteLine(text);
}

public DynamicMetaObject GetMetaObject(Expression parameter)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Linq;
using KingAOP.Aspects;

namespace KingAOP.Examples.HelloWorld
{
class NotNullInvocationAspect : MethodInterceptionAspect
{
public override void OnInvoke(MethodInterceptionArgs args)
{
if (args.Arguments.Any(arg => arg == null)) Console.WriteLine("\n" + args.Method + " can't be called because some of args is null");

else args.Proceed();
}
}
}
1 change: 1 addition & 0 deletions examples/VS 2010/KingAOP.Examples/KingAOP.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Compile Include="ExceptionHandling\PublicService.cs" />
<Compile Include="HelloWorld\HelloWorld.cs" />
<Compile Include="HelloWorld\HelloWorldAspect.cs" />
<Compile Include="HelloWorld\NotNullInvocationAspect.cs" />
<Compile Include="InterceptInvocation\ArgumentValidationAspect.cs" />
<Compile Include="Logging\LoggingAspect.cs" />
<Compile Include="Logging\TestRepository.cs" />
Expand Down
4 changes: 4 additions & 0 deletions examples/VS 2010/KingAOP.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ static void Main(string[] args)
// hello world example
dynamic helloWorld = new HelloWorld.HelloWorld();
helloWorld.HelloWorldCall();

string text = "test";
helloWorld.PrintIfArgNotNull(text);
helloWorld.PrintIfArgNotNull(null);

// logging example
var entity = new TestEntity {Name = "Jon", Number = 99};
Expand Down

0 comments on commit 99574e4

Please sign in to comment.