public string SerializeObject(Colecao toSerialize) { XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType()); using (StringWriter textWriter = new StringWriter()) { xmlSerializer.Serialize(textWriter, toSerialize); return(textWriter.ToString()); } }
public static string SerializarColecao(this Colecao colecao) { try { XmlSerializer xmlSerializer = new XmlSerializer(colecao.GetType()); using (StringWriter textWriter = new StringWriter()) { xmlSerializer.Serialize(textWriter, colecao); return(textWriter.ToString()); } } catch (Exception) { return(""); } }