From 7a8506a8bb612d11dc8aea9d462002063383bda6 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 27 Nov 2025 11:39:51 +0000 Subject: [PATCH] Prohibit applying Conditional to property/event accessors Fixes #912 --- standard/attributes.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/standard/attributes.md b/standard/attributes.md index 2e9e22c51..a6c029e21 100644 --- a/standard/attributes.md +++ b/standard/attributes.md @@ -543,11 +543,14 @@ A call to a conditional method is included if one or more of its associated cond A conditional method is subject to the following restrictions: - The conditional method shall be a method in a *class_declaration* or *struct_declaration*. A compile-time error occurs if the `Conditional` attribute is specified on a method in an interface declaration. +- The conditional method shall not be an event or property accessor. - The conditional method shall have a return type of `void`. - The conditional method shall not be marked with the `override` modifier. A conditional method can be marked with the `virtual` modifier, however. Overrides of such a method are implicitly conditional, and shall not be explicitly marked with a `Conditional` attribute. - The conditional method shall not be an implementation of an interface method. Otherwise, a compile-time error occurs. - The parameters of the conditional method shall not be output parameters. +> *Note*: Attributes with an `AttributeUsage` ([ยง23.2.2](attributes.md#2322-attribute-usage)) including `AttributeTargets.Method` can normally be applied to property accessors and event accessors. The restrictions above prohibit this usage of the `Conditional` attribute. *end note* + In addition, a compile-time error occurs if a delegate is created from a conditional method. > *Example*: The example