0

I am creating a Parser assembly in C# to parse a XML structure. I have a XML schema defined for the XML files.

Using XSD tool I have created Class structures from XML Schema. The XML has various level hierarchy. So there are lot of class structures available.

Now In my Parser assembly I have serialize code which deserializes the XML file and provides the object of the top level class object which intern will have next level objects.

I want to provide APIs to the clients which are accessing my assembly. So after deserialzing the XML, I store top level object in my parser and access the object from where ever it is required. So I will be providing multiple APIs in my parser class itself to get the data. Is it right to keep methods to access data in Parser itself? or can I implement methods in corresponding classes which were generated using XSD tool?

Is there any common design approach which can be used for this case?

  • 1
    Is it right to keep methods to access data in Parser itself? or can I implement methods in corresponding classes which were generated using XSD tool? -- That decision is entirely yours to make, based on your specific requirements. Which approach works better for you? – Robert Harvey Jun 13 '18 at 14:59
2

AFAIK the generated classes are all partial, so technically you can add own methods to them easily in separate files, which don't get lost when you regenerate the classes again. As an alternative, you can also use extension methods, or simply additional classes apart from the generated ones.

However, which of those methods you are going to expose in public to the clients of your API is up to you - it is a decision you have to make, by knowing the individual requirements of your project. Methods which make only sense for your parser are probably not good candidates to be exposed. Methods which may be reused in other contexts can be sensible candidates. But for making a decision, one must know the individual methods and the individual context.

But when in doubt, speak to your clients what they expect from your API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.