This "ref mode" variable that implicitly defines so sort of state will make this hard for anyone else to understand this code. If something like this absolutely can't be avoided then maybe a member variable "XMLSerializationExportStateType (enum { ThisState, ThatState, etc.} )" that explicitly defines what this states are would be better/more self-documenting.