Skip to content

Instantly share code, notes, and snippets.

@meziantou
meziantou / CustomAuthorizeAttribute.cs
Last active October 31, 2023 08:37
Custom `AuthorizeAttribute` that allows boolean operators such as AND, OR, XOR, NOT
/// <summary>
/// [CustomAuthorize(Roles = "A && (!B || C) ^ D")]
/// </summary>
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
/*
* Exp -> SubExp '&&' Exp // AND
* Exp -> SubExp '||' Exp // OR
* Exp -> SubExp '^' Exp // XOR
* SubExp -> '(' Exp ')'