From adce5f7bdeeece83d7dbdcfbdc36d0ad1cf4ad7f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Jul 2026 22:03:45 +0000 Subject: [PATCH 1/3] Initial plan From e804859f019ac8e83009291c1c454a39d156ef45 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Jul 2026 22:06:09 +0000 Subject: [PATCH 2/3] docs: Add private accessor tip to CS8080 property-declaration-errors --- .../compiler-messages/property-declaration-errors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/compiler-messages/property-declaration-errors.md b/docs/csharp/language-reference/compiler-messages/property-declaration-errors.md index e7437efc66830..a73cb6ee8c2d7 100644 --- a/docs/csharp/language-reference/compiler-messages/property-declaration-errors.md +++ b/docs/csharp/language-reference/compiler-messages/property-declaration-errors.md @@ -234,7 +234,7 @@ These errors enforce the rules for overriding properties in derived classes. For - Ensure the member you're overriding is a property, not a field or method (**CS0544**). The `override` keyword on a property can only target a `virtual`, `abstract`, or `override` property in a base class. To shadow a non-property member with a property, use the `new` keyword instead of `override`. - Override only the accessors that exist in the base class property declaration (**CS0545**, **CS0546**). You can't override a property accessor that isn't present or accessible in the base class because there's no virtual method to override. If the base class property has only a `get` accessor, you can't add a `set` accessor through an override. Either add the missing accessor to the base class and mark it `virtual`, or use `new` to hide the base class property with a new property definition. - Match the type of the overriding property to the type of the overridden member (**CS1715**). Read-only (`get`-only) properties support covariant return types beginning with C# 9, so the override can return a more derived type. However, properties that have a `set` or `init` accessor require an exact type match because the setter accepts values of the declared type. If you need a different type on a property with a setter, change the property type in the derived class to match the base class declaration, or remove the setter and use a covariant return type instead. -- Include all accessors from the base property when overriding with an auto-implemented property (**CS8080**). Auto-implemented properties generate both storage and accessor implementations, so they must override all accessors present in the base class. If the base property has both `get` and `set`, the auto-implemented override must also have both. To override only specific accessors, implement the property with explicit accessor bodies and an explicit backing field instead of using auto-implementation. +- Include all accessors from the base property when overriding with an auto-implemented property (**CS8080**). Auto-implemented properties generate both storage and accessor implementations, so they must override all accessors present in the base class. If the base property has both `get` and `set`, the auto-implemented override must also have both. To override only specific accessors, implement the property with explicit accessor bodies and an explicit backing field instead of using auto-implementation. If the base class property has a `private` accessor—for example, `public virtual int Member { get; private set; }`—you can't include that accessor in a derived class override because `private` members aren't accessible outside the declaring class. In that case, you must use explicit accessor bodies for the override instead of an auto-implemented property. For example, `public override int Member { get => base.Member; }` provides only the `get` accessor body without attempting to override the inaccessible private setter. For more information, see [Inheritance](../../fundamentals/object-oriented/inheritance.md), [Properties](../../programming-guide/classes-and-structs/properties.md), and [Using Properties](../../programming-guide/classes-and-structs/using-properties.md). From 1a0700a1622bb1d3ac68fe2aa055df44367da093 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Jul 2026 22:29:28 +0000 Subject: [PATCH 3/3] docs: Simplify CS8080 private accessor note per review feedback --- .../compiler-messages/property-declaration-errors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/compiler-messages/property-declaration-errors.md b/docs/csharp/language-reference/compiler-messages/property-declaration-errors.md index a73cb6ee8c2d7..35b8284694f1b 100644 --- a/docs/csharp/language-reference/compiler-messages/property-declaration-errors.md +++ b/docs/csharp/language-reference/compiler-messages/property-declaration-errors.md @@ -234,7 +234,7 @@ These errors enforce the rules for overriding properties in derived classes. For - Ensure the member you're overriding is a property, not a field or method (**CS0544**). The `override` keyword on a property can only target a `virtual`, `abstract`, or `override` property in a base class. To shadow a non-property member with a property, use the `new` keyword instead of `override`. - Override only the accessors that exist in the base class property declaration (**CS0545**, **CS0546**). You can't override a property accessor that isn't present or accessible in the base class because there's no virtual method to override. If the base class property has only a `get` accessor, you can't add a `set` accessor through an override. Either add the missing accessor to the base class and mark it `virtual`, or use `new` to hide the base class property with a new property definition. - Match the type of the overriding property to the type of the overridden member (**CS1715**). Read-only (`get`-only) properties support covariant return types beginning with C# 9, so the override can return a more derived type. However, properties that have a `set` or `init` accessor require an exact type match because the setter accepts values of the declared type. If you need a different type on a property with a setter, change the property type in the derived class to match the base class declaration, or remove the setter and use a covariant return type instead. -- Include all accessors from the base property when overriding with an auto-implemented property (**CS8080**). Auto-implemented properties generate both storage and accessor implementations, so they must override all accessors present in the base class. If the base property has both `get` and `set`, the auto-implemented override must also have both. To override only specific accessors, implement the property with explicit accessor bodies and an explicit backing field instead of using auto-implementation. If the base class property has a `private` accessor—for example, `public virtual int Member { get; private set; }`—you can't include that accessor in a derived class override because `private` members aren't accessible outside the declaring class. In that case, you must use explicit accessor bodies for the override instead of an auto-implemented property. For example, `public override int Member { get => base.Member; }` provides only the `get` accessor body without attempting to override the inaccessible private setter. +- Include all accessors from the base property when overriding with an auto-implemented property (**CS8080**). Auto-implemented properties generate both storage and accessor implementations, so they must override all accessors present in the base class. If the base property has both `get` and `set`, the auto-implemented override must also have both. To override only specific accessors, implement the property with explicit accessor bodies and an explicit backing field instead of using auto-implementation. If the base class property has a `private` accessor, you can't override the property with an auto-implemented property—use explicit accessor bodies instead. For more information, see [Inheritance](../../fundamentals/object-oriented/inheritance.md), [Properties](../../programming-guide/classes-and-structs/properties.md), and [Using Properties](../../programming-guide/classes-and-structs/using-properties.md).