I would like to check by attribute that value passed to method is correct, because adding if condition to method body make code less readable (in my opinion)
For example,
public object GetSomething(int id)
{
// there could be more conditions
if (id<= 0)
throw new ArgumentOutOfRangeException(nameof(id), $"Forbiden value: '{id}'");
// real logic
...
I want to check it is such way
[PossitiveValueAttr(id)]
public object GetSomething(int id)
{
// real logic
or (I would prefer that)
public object GetSomething([PossitiveValueAttr] int id)
{
// real logic
1) Do you know any similar existing solution?
2) How can I pass method's argument to my attribute?