Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ide
- {
- public ide() { }
- public string cUF { get; set; }
- public string tpAmb { get; set; }
- public string tpEmit { get; set; }
- public string tpTransp { get; set; }
- public string mod { get; set; }
- public string serie { get; set; }
- public string nMDF { get; set; }
- public string cMDF { get; set; }
- public int cDV { get; set; }
- public string modal { get; set; }
- public string dhEmi { get; set; }
- public string tpEmis { get; set; }
- public string procEmi { get; set; }
- public string verProc { get; set; }
- public string UFIni { get; set; }
- public string UFFim { get; set; }
- public List<infMunCarrega> InfMunCarrega { get; set; }
- public class infMunCarrega
- {
- public infMunCarrega()
- {
- }
- public int cMunCarrega { get; set; }
- public string xMunCarrega { get; set; }
- }
- }
- public class MdfeFuncoes
- {
- private void objetoParaXML(XmlWriter xmlWriter, object objeto, bool ignorarDeclaracaoElemento)
- {
- if (objeto == null)
- return;
- Type tipoObjeto;
- tipoObjeto = objeto.GetType();
- PropertyInfo[] propriedades;
- propriedades = tipoObjeto.GetProperties();
- if (!ignorarDeclaracaoElemento)
- xmlWriter.WriteStartElement(tipoObjeto.Name);
- foreach (PropertyInfo propriedade in propriedades)
- {
- if (Funcoes.novaTag(propriedade) && !(propriedade.GetValue(objeto, null) == null))
- {
- objetoParaXML(xmlWriter, propriedade.GetValue(objeto, null), false);
- continue;
- }
- object[] obj = propriedade.GetCustomAttributes(false);
- Funcoes.gravarElemento(xmlWriter, propriedade.Name, propriedade.GetValue(objeto, null), obj);
- }
- if (!ignorarDeclaracaoElemento)
- xmlWriter.WriteEndElement();
- }
- public XmlDocument GerarXml()
- {
- XmlWriterSettings configXML = new XmlWriterSettings();
- configXML.Indent = true;
- configXML.IndentChars = "";
- configXML.NewLineOnAttributes = false;
- configXML.OmitXmlDeclaration = false;
- Stream xmlSaida = new MemoryStream();
- XmlWriter oXmlGravar = XmlWriter.Create(xmlSaida, configXML);
- oXmlGravar.WriteStartDocument();
- oXmlGravar.WriteStartElement("MDFe", "http://www.portalfiscal.inf.br/mdfe");
- oXmlGravar.WriteStartElement("infMDFe");
- oXmlGravar.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
- oXmlGravar.WriteAttributeString("Id", "MDFe" + Id.ToString());
- oXmlGravar.WriteAttributeString("versao", "3.00");
- Type tipoObjeto;
- tipoObjeto = infMDFe.Ide.GetType();
- PropertyInfo[] propriedades;
- propriedades = tipoObjeto.GetProperties();
- objetoParaXML(oXmlGravar, infMDFe.Ide, false);
- objetoParaXML(oXmlGravar, infMDFe.Emit, false);
- //oXmlGravar.WriteStartElement("infModal"); //abre o infModal
- //oXmlGravar.WriteAttributeString("versaoModal", null, "3.00");
- //objetoParaXML(oXmlGravar, infMDFe.Rodo, false);
- //oXmlGravar.WriteEndElement(); //fecha o infModal
- //oXmlGravar.WriteStartElement("infDoc"); //abre o infDoc
- //if (infMDFe.InfDoc.InfMunDescarga != null)
- //{
- // foreach (infMDFe.infDoc.infMunDescarga docDescarga in infMDFe.InfDoc.InfMunDescarga)
- // {
- // objetoParaXML(oXmlGravar, docDescarga, false);
- // }
- //}
- //oXmlGravar.WriteEndElement(); //fecha o infDoc
- //objetoParaXML(oXmlGravar, infMDFe.Seg, false);
- //objetoParaXML(oXmlGravar, infMDFe.Tot, false);
- //if (infMDFe.Lacres != null)
- //{
- // foreach (infMDFe.lacres Lacres in infMDFe.Lacres)
- // {
- // objetoParaXML(oXmlGravar, Lacres, false);
- // }
- //}
- //if (infMDFe.AutXML != null)
- //{
- // objetoParaXML(oXmlGravar, infMDFe.AutXML, false);
- //}
- //if (infMDFe.InfAdic != null)
- //{
- // objetoParaXML(oXmlGravar, infMDFe.InfAdic, false);
- //}
- oXmlGravar.WriteEndElement(); //fecha infMDFe
- oXmlGravar.WriteEndElement(); //fecha MDFe
- oXmlGravar.Flush();
- xmlSaida.Flush();
- xmlSaida.Position = 0;
- XmlDocument documento = new XmlDocument();
- documento.Load(xmlSaida);
- oXmlGravar.Close();
- return documento;
- }
- } //o código continua, mas eu resolvendo essa falha no List<T>, dou conta do resto...
Add Comment
Please, Sign In to add comment