I have these codes which deserialize xml files into C# objects for further processing. All these works. But the problem is there are two different types of xml files. One for monthly and one for daily. The xml schemas for these two files are different but some schemas are the same.
This is the code
var serializer = new XmlSerializer(typeof(Daily.ABC));
using (TextReader reader = new StreamReader(new FileStream(filePath, FileMode.Open)))
{
var pfaCollection = (Daily.ABC)serializer.Deserialize(reader);
foreach (var entity in pfaCollection.Records.Entity)
{
IngestEntity(entity);
}
}
and this is for monthly:
var serializer = new XmlSerializer(typeof(Monthly.Entity.ABC));
using (TextReader reader = new StreamReader(new FileStream(filePath, FileMode.Open)))
{
var pfaCollection = (Monthly.Entity.ABC)serializer.Deserialize(reader);
foreach (var entity in pfaCollection.Entity)
{
IngestEntity(entity);
}
}
As you can see the classes are different but since there are some common schema, I created a method for both. DRY. And my IngestEntity method is below:
private void IngestEntity(? EntityData){}