[PATCH] D148467: [clang-format] Add a new AfterCSharpProperty to BraceWrapping
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 19 03:50:05 PDT 2023
MyDeveloperDay added a comment.
There is more to this than meets the eye.. what we have so far, from existing `AfterFunction` use and the propsed here `AfterCSharpProperty` is...
public Foo
{ <--- controlled by **AfterFunction **(rightly or wrongly)
get { <--- proposing to controlled by **AfterCSharpProperty**
return;
}
set {
val= value;
}
}
But for trivial Properties, these are automatically assumed to be wanted on the same line.
public Foo { set; get}
Trivial Properties are defined as:
all ordering variants (public/internal/private)
set;get;
public set;get
public init;get
get;set
My problem is AfterFunction ONLY kicks in if this isn't a TrivialProperty.. We can't currently force TrivialProperties to be handled differently.
AfterFunction = true we get
public Foo { set; get}
// we can't get to
public Foo {
set; get
}
Handling of Trivial Properties I feel there should be an "**AllowCSharpPropertiesOnASingleLine**" to match other options, otherwise it should follow AfterFunction (**AllowCSharpPropertiesOnASingleLine **default would need to be **true **to match current behaviour)
**AllowCSharpPropertiesOnASingleLine **=true, **AfterFunction **= true/false
public Foo { set; get }
**AllowCSharpPropertiesOnASingleLine **= false, **AfterFunction **= true
public Foo {
set; get
}
So then how do we handle
set;get
vs
set;
get;
Should **AfterCSharpProperty **be use in this case? or do we introduce "**BreakBetweenCSharpProperties **" (default false)
I know it seems strange to add 3 options to handle this, but I think it would give people the best of both worlds
you can have the following in the same file (which is actually quite common)
**BreakBetweenCSharpProperties **= false
**AllowCSharpPropertiesOnASingleLine **= true
**AfterFunction **= true
**AfterCSharpProperty **= true
public Foo
{
get
{
return value;
}
set {
value = 123;
}
}
public Bar
{
get; set;
}
If we use**AfterCSharpProperty ** to control **BreakBetweenCSharpProperties **then I think we have to have the following and we can't control Bar how we might want
public Foo
{
get
{
return value;
}
set {
value = 123;
}
}
public Bar
{
get;
set;
}
>From what I can tell...Microsoft .NET Framework seems to be
**BreakBetweenCSharpProperties **= true
**AllowCSharpPropertiesOnASingleLine **= false
**AfterFunction **= true
**AfterCSharpProperty **= true
https://github.com/microsoft/referencesource/blob/5697c29004a34d80acdaf5742d7e699022c64ecd/mscorlib/system/iappdomainsetup.cs
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-properties
It would seem they don't seem to put Trivial Properties/AutoProperties on the same line
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148467/new/
https://reviews.llvm.org/D148467
More information about the cfe-commits
mailing list