How to create an aspect checking for null references on all methods in a class in postsharp.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test
{
[MethodParameterNullCheck]
internal class Class
{
public Class()
{
}
public void MethodA(int i, ClassA a, ClassB b)
{
//Some business logic
}
}
}
The aspect [MethodParameterNullCheck] should then unfold to the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test
{
[MethodParameterNullCheck]
internal class Class
{
public Class()
{
}
public void MethodA(int i, ClassA a, ClassB b)
{
if (a == null) throw new ArgumentNullException("Class->MethodA: Argument a of ClassA is not allowed to be null.");
if (b == null) throw new ArgumentNullException("Class->MethodA: Argument b of ClassB is not allowed to be null.");
// Some Business Logic
}
}
}
I will appreciate if you can give me a sample implementation on this to get me startet on AOP with postsharp.