jeudi 3 mars 2016

Generate XML or JSON given a C# class

Hoping that this isn't going to run foul of the "recommend or find a tool, library or favourite off-site resource" off-topic rule but here goes anyway.

If you do database development then you'll likely be familiar with tools that are out there to put sample data into your tables to allow for testing.

I'm wondering if there's any way[0] that one can take a model class marked as Serializable and generate sample XML or JSON from the properties decorated with the appropriate attributes.

There are plenty questions both on SO and elsewhere about generating C# classes from JSON or XML but what I want is slightly different.

The specific use case here is that I'm waiting on JSON output from another developer and wondering if there's a way I can get a jumpstart so I can test my code, using this method, whatever this method may be.

I'm just using the standard XML serialiser and JSON.NET libraries but can switch to something else if needed.

[0] I know I can write code that can instantiate a class using Reflection, then reflect into that instance and write XML or JSON that way, but that's a big project in and of itself. I'm hoping for a pre-existing way in the .NET Framework or some kind of a FOSS tool





Aucun commentaire:

Enregistrer un commentaire