Hi,
I have a problem with validation of License in the server side of our application.
What I want is when the method
CreateProject(User user)
is invoked
Behind the scenes that will lead to check with the License service if the user has license to create new project, in case the user has no permission that will lead to exception.
If I'm right there way to do it with c#'s mechanism named:
ValidationAttribute
Am i right? If yes, how to do it? If no, what the right way?
What I have tried:
When I've tried to write a small program it's not working.
the program as below:
The MyValidationAttribute attribute definition:
[AttributeUsage(AttributeTargets.Method)]
public class MyValidationAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
int id = (int)value;
if (id > 0)
return true;
throw new Exception("Error");
}
}
The service to validate:
public class Service
{
[MyValidation]
public bool GetService(int id)
{
if (id > 100)
{
return true;
}
return false;
}
}
The main uses this service:
static void Main(string[] args)
{
Service service = new Service();
service.GetService(-8);
}
But even with negative id the service does non throws exception.
Thanks!