Well, I'm trying to read for importing% of Electronic Bills and I'm having a hard time decapsulating the XMLs
of blessed.
No problem getting to the object ICMS
:
object objeto = ListaItens[i].imposto.Items[0]
This returns an object of type ICMS
and here is the description of this class:
public partial class TNFeInfNFeDetImpostoICMS {
private object itemField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ICMS00", typeof(TNFeInfNFeDetImpostoICMSICMS00))]
[System.Xml.Serialization.XmlElementAttribute("ICMS10", typeof(TNFeInfNFeDetImpostoICMSICMS10))]
[System.Xml.Serialization.XmlElementAttribute("ICMS20", typeof(TNFeInfNFeDetImpostoICMSICMS20))]
[System.Xml.Serialization.XmlElementAttribute("ICMS30", typeof(TNFeInfNFeDetImpostoICMSICMS30))]
[System.Xml.Serialization.XmlElementAttribute("ICMS40", typeof(TNFeInfNFeDetImpostoICMSICMS40))]
[System.Xml.Serialization.XmlElementAttribute("ICMS51", typeof(TNFeInfNFeDetImpostoICMSICMS51))]
[System.Xml.Serialization.XmlElementAttribute("ICMS60", typeof(TNFeInfNFeDetImpostoICMSICMS60))]
[System.Xml.Serialization.XmlElementAttribute("ICMS70", typeof(TNFeInfNFeDetImpostoICMSICMS70))]
[System.Xml.Serialization.XmlElementAttribute("ICMS90", typeof(TNFeInfNFeDetImpostoICMSICMS90))]
[System.Xml.Serialization.XmlElementAttribute("ICMSPart", typeof(TNFeInfNFeDetImpostoICMSICMSPart))]
[System.Xml.Serialization.XmlElementAttribute("ICMSSN101", typeof(TNFeInfNFeDetImpostoICMSICMSSN101))]
[System.Xml.Serialization.XmlElementAttribute("ICMSSN102", typeof(TNFeInfNFeDetImpostoICMSICMSSN102))]
[System.Xml.Serialization.XmlElementAttribute("ICMSSN201", typeof(TNFeInfNFeDetImpostoICMSICMSSN201))]
[System.Xml.Serialization.XmlElementAttribute("ICMSSN202", typeof(TNFeInfNFeDetImpostoICMSICMSSN202))]
[System.Xml.Serialization.XmlElementAttribute("ICMSSN500", typeof(TNFeInfNFeDetImpostoICMSICMSSN500))]
[System.Xml.Serialization.XmlElementAttribute("ICMSSN900", typeof(TNFeInfNFeDetImpostoICMSICMSSN900))]
[System.Xml.Serialization.XmlElementAttribute("ICMSST", typeof(TNFeInfNFeDetImpostoICMSICMSST))]
public object Item {
get {
return this.itemField;
}
set {
this.itemField = value;
}
}
}
What I would like to do is to scan all "types" of TNFeInfNFeDetImpostoICMS
to get their properties, but I do not find any way to loop ICMS
by uncapping each element.
Can you help?
for
One thing I realized in practice (I do not have a lot of fiscal knowledge) is that every item in EDIT:
will only contain one of these XML
encapsulated classes, so you only need to find a way for the program to do ICMS
of the object by choosing at runtime the contained class. Is there any way to do this?
unbox
I perform deserialization as follows:
I have a class EDIT2:
:
public static class Serializer
{
public static T Deserialize<T>(this XElement xElement)
{
using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(xElement.ToString())))
{
var xmlSerializer = new XmlSerializer(typeof(T));
return (T)xmlSerializer.Deserialize(memoryStream);
}
}
public static XElement Serialize<T>(this object o)
{
using (var memoryStream = new MemoryStream())
{
using (TextWriter streamWriter = new StreamWriter(memoryStream))
{
var xmlSerializer = new XmlSerializer(typeof(T));
xmlSerializer.Serialize(streamWriter, o);
return XElement.Parse(Encoding.ASCII.GetString(memoryStream.ToArray()));
}
}
}
}
And a Serializer
class generated from ProcNFe_v3_10
that I got on the farm site (I will not post because it is too long).
Then first I load a .xsd
with my XElement
:
XElement xElement = XElement.Load(ofdXml.FileName);
Being .xml
a ofdXml
.
And then I call the OpenFileDialog
method of my class passing deserializer
to type TNfeProc
(which is the corresponding type of my note contained within the T
class) and ProcNFe_v3_10
loaded as an attribute, as follows:
TNfeProc NFCarregada = Serializer.Deserialize<TNfeProc>(xElement);
And voilà, I have my xElement
deserialized.