2 ms·
The C# (and presumably VB) compiler just looks for an attribute with the right namespace and name (System.Runtime.CompilerServices.ExtensionAttribute). If you'r
by MichaelGG 14y ago
The C# (and presumably VB) compiler just looks for an attribute with the right namespace and name (System.Runtime.CompilerServices.ExtensionAttribute). If you're using .NET 2.0 you can get extension methods just by declaring you own attribute with that name and using it.
This is also another area where C# took a narrow view of language features and implemented the bare minimum needed to get LINQ working. Why not take a general view of type extensions, and support type extensions as a proper feature versus a hack for LINQ? That is, support all members, including static members, for type extensions.
- kvb 14y agoI also prefer F#'s more general approach, which allows all kinds of extension members (static or instance, methods, properties, and events). But members of the C# team have repeatedly explained that they were the "long pole" during the LINQ work, so I think it's perfectly understandable that they took a more limited approach.
- MichaelGG 14y agoThat explanation works for C# 3, but there have been two major releases since, which added relatively little to the language. They could have rounded out the LINQ-only stuff by now.
- com2kid 14y agoC# 4.0 brought support for Dynamic, a pretty damn big change. And of course optional and default parameters, another huge boon. Then C# 5.0 brought Async, a huge feature. In terms of making the language more powerful I would call those on par with extending out extension methods.
- magic_haze 14y agoAnd I think most of the compiler team has been busy with roslyn, which sounds like a pretty big rewrite.