This project is read-only.

Allow extension methods EVERYWHERE

Topics: C# Language Design
May 2, 2014 at 1:37 PM
Edited May 2, 2014 at 1:37 PM
Extension methods restrictions are exceedingly silly. Static classes, non-nested classes. I should be able to define static methods any time i want to

Class Car {
//car stuff

private Car ToCar(this string carSerialized)
return car

This is by far the most common need for an extension method inside of a class. I always try to write code as human readable english:

var car = carInfo.ToCar() as opposed to
var car = ToCar(carInfo)

I wouldn't want to create a highly visible extension on string thereby polluting all string usages. There really is no acceptable reason I can't just define extension methods anywhere i want.

if the compiler needs to generate a meaningless shell/wrapper class and lift pieces around in arbitrary nonsensical ways, that's what compilers are for.