-
Notifications
You must be signed in to change notification settings - Fork 25.1k
-
Code from documentation here.
I'm not sure if I'm right but I just want to know if we can do this.
Instead of this:
internal class MinimumAgeAuthorizeAttribute : AuthorizeAttribute
{
const string POLICY_PREFIX = "MinimumAge";
public MinimumAgeAuthorizeAttribute(int age) => Age = age;
// Get or set the Age property by manipulating the underlying Policy property
public int Age
{
get
{
if (int.TryParse(Policy.Substring(POLICY_PREFIX.Length), out var age))
{
return age;
}
return default(int);
}
set
{
Policy = $"{POLICY_PREFIX}{value.ToString()}";
}
}
Can we just do this?
public class MinimumAgeAuthorizeAttribute : AuthorizeAttribute
{
const string POLICY_PREFIX = "MinimumAge";
private readonly int _age;
public MinimumAgeAuthorizeAttribute(int age)
{
_age = age;
Policy = $"{POLICY_PREFIX}{age}";
}
public int Age => _age;
}
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment