SobekCM.Core.UI_Configuration.Citation.CitationFieldSet.Append_Element C# (CSharp) Method

Append_Element() public method

Adds a new citation element to the end of the current elements in this field set
If an element exists with the same MetadataTerm, it is removed first.
public Append_Element ( CitationElement NewElement ) : void
NewElement CitationElement New citation element to add
return void
        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;
        }