What is member level at surface look?
bravequickcleverfibreyarn opened this issue · 2 comments
Type of issue
Typo
Description
From https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/partial-member,
A partial member has one declaring declaration and often one implementing declaration. The declaring declaration doesn't include a body. The implementing declaration provides the body of the member.
This guidelines is technically right. Since setter and getter is "decoupled" by compilation, but I think by member is usually meant property/indexer as whole. Close this straightly if I am wrong.
As top surface property/indexer has body. What does not have body are accessors.
// declarations, no body on accessors
// declaring property/indexer w/o body = Error CS0548 'Class.Member': property or indexer must have at least one accessor
// only methods are body-less
internal partial class Test
{
public partial int this[int i] { get; set; }
public partial int GetterOnly { get; }
public partial int SetterOnly { set; }
public partial int Both { set; get; }
partial void AAA();
private partial void BBB();
}
internal partial class Test
{
// implementations, accessors with body
public partial int this[int i] { get => 9; set { } }
public partial int GetterOnly { get => 1; }
public partial int SetterOnly { set { } }
public partial int Both { set { } get => 7; }
private partial void BBB() { }
}
Page URL
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/partial-member
Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/language-reference/keywords/partial-member.md
Document Version Independent Id
85bf7eb0-b476-94b6-e10a-d0f42fee407b
Article author
Metadata
- ID: b4eedbc9-36be-6c79-fcb4-d5fe6998e5b1
- Service: dotnet-csharp
- Sub-service: lang-reference
In this instance, I think the current language is clear, and reasonably concise. The "declaring declaration" defines which accessors must be implemented (get
, set
, or both). The "implementing declaration" must implement the same set. (Even that kind of fudges it because init
could be used in place of set
.)
I'll close this, but I'll keep watching for other potential confusion.
Okay. I agree. Thanks for clarification.