Replies: 6 comments 23 replies
-
extension<T> (T) where T : class?
{
[param:NotNull] public void ThrowIfNull() => ArgumentNullException.ThrowIfNull(this);
} The |
Beta Was this translation helpful? Give feedback.
-
How is public static class CSharpExtensions
{
extension
{
public bool (SyntaxToken).IsKind(SyntaxKind kind) => ...;
public bool (SyntaxTrivia).IsKind(SyntaxKind kind) => ...;
[param: NotNullWhen(true)]
public bool (SyntaxNode?).IsKind(SyntaxKind kind) => ...;
public bool (SyntaxNodeOrToken).IsKind(SyntaxKind kind) => ...;
public bool (SyntaxNode).ContainsDirective(SyntaxKind kind) => ...;
}
} any better than the old public static class CSharpExtensions
{
public static bool IsKind(this SyntaxToken token, SyntaxKind kind) => ...;
public static bool IsKind(this SyntaxTrivia trivia, SyntaxKind kind) => ...;
public static bool IsKind([NotNullWhen(true)] this SyntaxNode? node, SyntaxKind kind) => ...;
public static bool IsKind(this SyntaxNodeOrToken nodeOrToken, SyntaxKind kind) => ...;
public static bool ContainsDirective(this SyntaxNode node, SyntaxKind kind) => ...;
} if the old extension method syntax will still be around? |
Beta Was this translation helpful? Give feedback.
-
I didn't say "entomology" to start with 😂 |
Beta Was this translation helpful? Give feedback.
-
Just added a comment on extensions proposal here. |
Beta Was this translation helpful? Give feedback.
-
I think there are some seriously flawed assumptions within this proposal:
As far as this programmer is concerned, the author is deeply mistaken. I always organise extension by the underlying type. Not doing so is messy and complicates the code in my view. Without clear empirical evidence, such guesses/beliefs risk delivering the wrong solution for the majority of devs. Also, I do not understand why these extensions are being embedded in a static class. For me, I'd far prefer the example shown with the code: public static class CSharpExtensions
{
extension(SyntaxToken)
{
public bool IsKind(SyntaxKind kind) => ...; were expressed as: public extension(SyntaxToken)
{
public bool IsKind(SyntaxKind kind) => ...;
}
public extension(SyntaxTrivia)
{
public bool IsKind(SyntaxKind kind) => ...;
}
public extension(SyntaxNode?)
{
[param: NotNullWhen(true)]
public bool IsKind(SyntaxKind kind) => ...;
}
public extension(SyntaxNodeOrToken)
{
public bool IsKind(SyntaxKind kind) => ...;
}
public extension(SyntaxNode)
{
public bool ContainsDirective(SyntaxKind kind) => ...;
} with the option to fall back to using public extension
{
public bool IsKind(this SyntaxToken token, SyntaxKind kind) => ...;
public bool IsKind(this SyntaxTrivia trivia, SyntaxKind kind) => ...;
public bool IsKind([NotNullWhen(true)] this SyntaxNode? node, SyntaxKind kind) => ...;
public bool IsKind(this SyntaxNodeOrToken nodeOrToken, SyntaxKind kind) => ...;
public bool ContainsDirective(this SyntaxNode node, SyntaxKind kind) => ...;
} The removal of all those noisy |
Beta Was this translation helpful? Give feedback.
-
Maybe I missed it, but in the new proposal how to do you statically call the new extension methods? Given they will be generated inside some form of unspeakable class. Being able to do call them statically is critical for disambiguation scenarios, no? |
Beta Was this translation helpful? Give feedback.
-
https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-11-13.md
Agenda
Beta Was this translation helpful? Give feedback.
All reactions