0
포스트 샤프의 클래스에있는 모든 메소드에서 널 참조를 검사하는 aspect를 작성하는 방법.포스트 클래스에서 클래스의 모든 메소드에 대해 null 참조를 검사하는 aspect를 작성하는 방법
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
}
}
}
가로 세로 [MethodParameterNullCheck] 다음 코드로 전개해야합니다
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
}
}
}
당신이 postsharp와 AOP에 나에게 startet을 얻기 위해 나에게 이것에 구현 샘플을 줄 수 있다면 나는 감사합니다. 다음
public static void ThrowIfNull<T>(this T obj, string parameterName) where T : class
{
if(obj == null) throw new ArgumentNullException(parameterName);
}
전화 :