Work Function and Electron Affinity of Semiconductors: Doping Effect and Complication due to Fermi Level Pinning