[Proposal] Inline type declaration without curly brackets #5513
Replies: 6 comments 26 replies
-
Especially for interfaces, they are suffering the lack of this feature while there's so many cases of declaring purely decorative interfaces. I remember this being discussed somewhere else too. And there also is some discussion about simplfying empty constructor declaration. Spoiler alert: many are whining that "it's just 2 characters, why bother so much". |
Beta Was this translation helpful? Give feedback.
-
Proposal updated, renamed class declaration to type declaration (now interfaces is in proposal) and new example class derived declaration with simplified constructor (flagged as extra, beacause i'm not sure if it need be a new proposal) |
Beta Was this translation helpful? Give feedback.
-
I don't see how saving literally one keystroke is valuable enough to change the language for it. |
Beta Was this translation helpful? Give feedback.
-
Running into this myself as well. It feels odd that this can be done with // What I have to write
public interface IFramebuffer : IDeviceObject, IDescribedObject<FramebufferDescription>, IDisposable
{
}
// What I want to write
public interface IFramebuffer : IDeviceObject, IDescribedObject<FramebufferDescription>, IDisposable; |
Beta Was this translation helpful? Give feedback.
-
Note that this directly conflicts with the proposals people have raised where they want type decls to work like namespaces (where you can use semicolon, but the scope is extendedto the end of the file. |
Beta Was this translation helpful? Give feedback.
-
Am I crazy or has this language feature now been implemented in C# 12 both for classes and interfaces? I'm testing this with .NET 8 RC2 and I can now omit the curly brackets for these types when they have an empty body. What is strange though is that I can't seem to find any more information about it either here on in the Roslyn repo but there's even a new Resharper rule for it called resharper_redundant_type_declaration_body_highlighting so I guess it must be true? Why is it so hard to find any more information about this if this is the case? Shouldn't it be listed here as a new language feature in C# 12?: https://github.com/dotnet/roslyn/blob/main/docs/Language%20Feature%20Status.md#c-120 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal
Currently we need declarate types using curly brackets even when is not used...
I propose be able to delcare types without brackets, just using semicolon.
Currently
record
s support this kind of declaration, as @DavidArno explains in #5513 (reply in thread)Pros
Cons
Extra
Maybe also could make even simple derived class with simple sintax.
Beta Was this translation helpful? Give feedback.
All reactions