MetadataSerialization class bug
I just realized, the MetadataSerialization works with a single task! I want multiple tasks; so I have to think of how I will do this. Essentially, what I envision is adding another class; MetadataSerialization is somewhat big in itself, and I'll create a root class above it. The first step will be to find out if it is being used. In VC#, I right-click over the class name and click Find All References.
So I have to change the interface to:
public MetadataElementCollection<T> LoadFromXml(string xml)
public MetadataElementCollection<T> LoadFromXmlFile(string path)
private MetadataElementCollection<T> LoadXml(XmlDocument doc) //Now loads the collection; previous method changed to LoadXmlElement
private T LoadXmlElement(XmlElement element) //Now loads a single element
public string SaveToXml(MetadataElementCollection<T> collection)
public void SaveToXmlFile(MetadataElementCollection<T> collection, string path)
SaveToXml was an easy change; I changed the root element and added an extra loop to loop through the collection. LoadXml previously is now LoadXmlElement to load a single element. I changed the parameter to deal with a single element. LoadXml now looks like this:
private MetadataElementCollection<T> LoadXml(XmlDocument doc)
{
MetadataElementCollection<T> collection = new MetadataElementCollection<T>();
foreach (XmlElement element in doc.ChildNodes)
{
T item = this.LoadXmlElement(element);
if (item != null)
collection.Add(item);
}
return collection;
}
You may wonder how I derive my collections; all collections that use MetadataElementCollection inherit from MetadataElementCollection<MetadataElement>, and so I can use this as a common denominating factor. Overall this was easy to accomplish. At least I was able to refactor the interface before anything made use of it. The only thing left to do is to change the tests, and test this new class out.