@@ -22,7 +22,7 @@ public class FeatureGateAttribute : ActionFilterAttribute, IAsyncPageFilter
2222 /// </summary>
2323 /// <param name="features">The names of the features that the attribute will represent.</param>
2424 public FeatureGateAttribute ( params string [ ] features )
25- : this ( RequirementType . All , features )
25+ : this ( RequirementType . All , false , features )
2626 {
2727 }
2828
@@ -32,6 +32,27 @@ public FeatureGateAttribute(params string[] features)
3232 /// <param name="requirementType">Specifies whether all or any of the provided features should be enabled in order to pass.</param>
3333 /// <param name="features">The names of the features that the attribute will represent.</param>
3434 public FeatureGateAttribute ( RequirementType requirementType , params string [ ] features )
35+ : this ( requirementType , false , features )
36+ {
37+ }
38+
39+ /// <summary>
40+ /// Creates an attribute that can be used to gate actions or pages. The gate can be configured to negate the evaluation result.
41+ /// </summary>
42+ /// <param name="negate">Specifies the evaluation for the provided features gate should be negated.</param>
43+ /// <param name="features">The names of the features that the attribute will represent.</param>
44+ public FeatureGateAttribute ( bool negate , params string [ ] features )
45+ : this ( RequirementType . All , negate , features )
46+ {
47+ }
48+
49+ /// <summary>
50+ /// Creates an attribute that can be used to gate actions or pages. The gate can be configured to require all or any of the provided feature(s) to pass or negate the evaluation result.
51+ /// </summary>
52+ /// <param name="requirementType">Specifies whether all or any of the provided features should be enabled in order to pass.</param>
53+ /// <param name="negate">Specifies the evaluation for the provided features gate should be negated.</param>
54+ /// <param name="features">The names of the features that the attribute will represent.</param>
55+ public FeatureGateAttribute ( RequirementType requirementType , bool negate , params string [ ] features )
3556 {
3657 if ( features == null || features . Length == 0 )
3758 {
@@ -41,14 +62,16 @@ public FeatureGateAttribute(RequirementType requirementType, params string[] fea
4162 Features = features ;
4263
4364 RequirementType = requirementType ;
65+
66+ Negate = negate ;
4467 }
4568
4669 /// <summary>
4770 /// Creates an attribute that will gate actions or pages unless all the provided feature(s) are enabled.
4871 /// </summary>
4972 /// <param name="features">A set of enums representing the features that the attribute will represent.</param>
5073 public FeatureGateAttribute ( params object [ ] features )
51- : this ( RequirementType . All , features )
74+ : this ( RequirementType . All , false , features )
5275 {
5376 }
5477
@@ -58,6 +81,27 @@ public FeatureGateAttribute(params object[] features)
5881 /// <param name="requirementType">Specifies whether all or any of the provided features should be enabled in order to pass.</param>
5982 /// <param name="features">A set of enums representing the features that the attribute will represent.</param>
6083 public FeatureGateAttribute ( RequirementType requirementType , params object [ ] features )
84+ : this ( requirementType , false , features )
85+ {
86+ }
87+
88+ /// <summary>
89+ /// Creates an attribute that can be used to gate actions or pages. The gate can be configured to negate the evaluation result.
90+ /// </summary>
91+ /// <param name="negate">Specifies the evaluation for the provided features gate should be negated.</param>
92+ /// <param name="features">A set of enums representing the features that the attribute will represent.</param>
93+ public FeatureGateAttribute ( bool negate , params object [ ] features )
94+ : this ( RequirementType . All , negate , features )
95+ {
96+ }
97+
98+ /// <summary>
99+ /// Creates an attribute that can be used to gate actions or pages. The gate can be configured to require all or any of the provided feature(s) to pass or negate the evaluation result.
100+ /// </summary>
101+ /// <param name="requirementType">Specifies whether all or any of the provided features should be enabled in order to pass.</param>
102+ /// <param name="negate">Specifies the evaluation for the provided features gate should be negated.</param>
103+ /// <param name="features">A set of enums representing the features that the attribute will represent.</param>
104+ public FeatureGateAttribute ( RequirementType requirementType , bool negate , params object [ ] features )
61105 {
62106 if ( features == null || features . Length == 0 )
63107 {
@@ -82,6 +126,8 @@ public FeatureGateAttribute(RequirementType requirementType, params object[] fea
82126 Features = fs ;
83127
84128 RequirementType = requirementType ;
129+
130+ Negate = negate ;
85131 }
86132
87133 /// <summary>
@@ -94,6 +140,11 @@ public FeatureGateAttribute(RequirementType requirementType, params object[] fea
94140 /// </summary>
95141 public RequirementType RequirementType { get ; }
96142
143+ /// <summary>
144+ /// Negates the evaluation for whether or not a feature gate should activate.
145+ /// </summary>
146+ public bool Negate { get ; }
147+
97148 /// <summary>
98149 /// Performs controller action pre-processing to ensure that any or all of the specified features are enabled.
99150 /// </summary>
@@ -110,6 +161,11 @@ public override async Task OnActionExecutionAsync(ActionExecutingContext context
110161 ? await Features . All ( async feature => await fm . IsEnabledAsync ( feature ) . ConfigureAwait ( false ) )
111162 : await Features . Any ( async feature => await fm . IsEnabledAsync ( feature ) . ConfigureAwait ( false ) ) ;
112163
164+ if ( Negate )
165+ {
166+ enabled = ! enabled ;
167+ }
168+
113169 if ( enabled )
114170 {
115171 await next ( ) . ConfigureAwait ( false ) ;
@@ -138,6 +194,11 @@ public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext contex
138194 ? await Features . All ( async feature => await fm . IsEnabledAsync ( feature ) . ConfigureAwait ( false ) )
139195 : await Features . Any ( async feature => await fm . IsEnabledAsync ( feature ) . ConfigureAwait ( false ) ) ;
140196
197+ if ( Negate )
198+ {
199+ enabled = ! enabled ;
200+ }
201+
141202 if ( enabled )
142203 {
143204 await next . Invoke ( ) . ConfigureAwait ( false ) ;
0 commit comments