public void Append_Element(CitationElement NewElement)
{
// Ensure the dictionary is built (i.e., not null)
if (elementsDictionary == null) elementsDictionary = new Dictionary<string, CitationElement>(StringComparer.OrdinalIgnoreCase);
// Check that the count in the dictionary seems right
if (elementsDictionary.Count != Elements.Count)
{
foreach (CitationElement thisElement in Elements)
elementsDictionary[thisElement.MetadataTerm] = thisElement;
}
// If this element already exists, remove it
if (elementsDictionary.ContainsKey(NewElement.MetadataTerm))
{
CitationElement existing = elementsDictionary[NewElement.MetadataTerm];
Elements.Remove(existing);
}
// Append the new one
Elements.Add(NewElement);
elementsDictionary[NewElement.MetadataTerm] = NewElement;
}