///////////////////////////////////////////////////////////////////////
/// <summary>Replaces or adds an extension of the given type
/// to the list.
///
/// This method looks for the first element on the list of the
/// given type and replaces it with the new value. If there are
/// no element of this type yet, a new element is added at the
/// end of the list.
/// </summary>
/// <param name="extensionElements">list of IExtensionElement</param>
/// <param name="type">type of the element to be added, removed
/// or replaced</param>
/// <param name="newValue">new value for this element, null to
/// remove it</param>
///////////////////////////////////////////////////////////////////////
public static void SetExtension(IList<IExtensionElementFactory> extensionElements,
Type type,
IExtensionElementFactory newValue)
{
int count = extensionElements.Count;
for (int i = 0; i < count; i++)
{
object element = extensionElements[i];
if (type.IsInstanceOfType(element))
{
if (newValue == null)
{
extensionElements.RemoveAt(i);
}
else
{
extensionElements[i] = newValue;
}
return;
}
}
if (newValue != null)
{
extensionElements.Add(newValue);
}
}