The original type of door switch, showing the typical corrosion that develops. Note it is only round the contact area (although this is possibly the effect of electricity in the junction accelerating the corrosion at this point)!
However if the contact is only intermittent and not failed completely it may be possible to recover. With the switch removed grasp the mounting ears in one hand and the socket for the wiring bullet in the other, and twist back and fore while pressing the two parts together to get a nice shiny contact surface as shown here.
Once you have a reliable electrical connection push the plunger to open the switch and daub Vaseline or grease between the two open halves of the contact, then slide on a suitable diameter sleeve. The fixed part is conveniently of a slightly larger diameter than the moving part, so choose your sleeving correctly and it will stay on the fixed part while allowing the moving part to slide in and out. If fitting a new switch then it makes sense to do the Vaseline/grease and sleeve bit from the word 'go'.
The non-standard switch, which was the only type available some years ago. This is actually better for the door as the plastic plunger is less likely to scratch through the paint, but the cylinder behind the mounting ears is a slightly larger diameter than the original so the hole had to be opened up. To do this with a drill the wire has to be pushed back out of the way (make sure you don't lose it (I didn't)), and touch up the edges with paint afterwards.
When my son bought one of his classic BMWs the owner advised him there was a problem with the courtesy lights flattening the battery as they were on all the time, so he had disconnected them. A quick check indicated a possible wiring short to earth somewhere between the two doors and the boot which would have been a pain to track down. However my son idly pushed the passenger door switch in with his finger while the door was open one day, and the lights went out! He looked at the face of the door frame that the switch bears on when the door is closed, and discovered there is a hole in that position that should have a plastic plug, so the switch doesn't scratch the paint, and the plug was missing that side!