Code maintenance

Asked

Viewed 82 times

1

I have an application that makes the deserialization of an XML file.

I managed a class with from an XSD with XSD.EXE

For deserialization I use the following code:

static T LoadFromXMLString<T>(string xmlText)
{
    var stringReader = new System.IO.StringReader(xmlText);
    var serializer = new XmlSerializer(typeof(T));
    return (T)serializer.Deserialize(stringReader);
}

I call him as follows:

var _ProcNFe = LoadFromXMLString<ProcNFe.TNfeProc>(XmlProcNFe);

After that, I use the object _ProcNFe to save some fields to the database.

However, a doubt has arisen, the XSD I originally used will be changed and consequently the generated class as well.

What would be correct, create a new class from this new version of XSD or change the existing one to conform to the new XSD?

  • 2

    I advise creating a new class and working with versioning, just like NF-e is also versioned (valid).

  • In this case, I believe you need to have a mapping between the file and a class so you can manipulate your data and update the database. So every time the file changes, you would need to have a class to represent it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.