The internet says that you should never change your lens in direct sunlight. This photo tip was started before digital cameras, when the only barrier between the light sensitive film and the sun was the shutter curtain. And the reasoning was: if you changed your lens in direct sunlight there might be a light leak which would expose your film and create problems. However by the 1980's, camera manufacturing had improved so that this was no longer a problem. Today with the digital sensor, as long as you have turned off your camera when swapping lenses, there should be no problems at all. The sensor is no longer seeing anything. It's off.
There was one point of caution a manufacturer did make in their literature about leaving your lens in the sun: FIRE! Yes, if you leave your lens out in the sun with both the front and back lens cap off, the sunlight may shine through the lens and focus the light on something flammable and poof - FIRE! So if you don't want your house to burn down don't leave your lens on the porch or near a window with direct sunlight with both lens caps off.
More useful advice would be to not change your lens in the rain!