JD2022-TU1/main/tools/framework/JD.TeaBoxAddinSystem/Addins/Description/ExtensionNodeDescriptionCollection.cs

77 lines
2.5 KiB
C#

using System;
using JD.Collections.Interfaces;
using JD.Kernel.StaticHelpers;
namespace JD.TeaBoxAddinSystem.Addins.Description
{
/// <summary>
/// Collection of <see cref="ExtensionNodeDescription"/>s
/// </summary>
internal class ExtensionNodeDescriptionCollection : AddinObjectCollection<ExtensionNodeDescription>, IKeyedList<string, ExtensionNodeDescription>
{
#region Properties
/// <summary>
/// Gets an <see cref="ExtensionNodeDescription"/> by its id.
/// </summary>
/// <remarks>
/// Not all <see cref="ExtensionNodeDescription"/>s have an id, and ids are not guaranteed to be unique.
/// This method will return the first <see cref="ExtensionNodeDescription"/> it finds with the given <paramref name="id"/>.
/// This method is O(N).</remarks>
/// <param name="id"></param>
/// <returns></returns>
public ExtensionNodeDescription this[string id]
{
get
{
Throw.IfEmpty(id, "id");
foreach (ExtensionNodeDescription description in this)
{
if (string.Equals(description.Id, id))
{
return description;
}
}
return null;
}
}
#endregion
#region Methods
/// <summary>
/// Returns if an <see cref="ExtensionNodeDescription"/> with the given <paramref name="id"/> is contained in this collection.
/// </summary>
/// <remarks>
/// Not all <see cref="ExtensionNodeDescription"/>s have an id, and ids are not guaranteed to be unique.
/// This method will return true as soon as it finds an <see cref="ExtensionNodeDescription"/> with the given <paramref name="id"/>.
/// This method is O(N).</remarks>
/// <param name="id"></param>
/// <returns></returns>
public bool ContainsKey(string id)
{
return (this[id] != null);
}
/// <summary>
/// Not supported.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool Remove(string id)
{
throw new NotSupportedException();
}
public bool TryGetValue(string key, out ExtensionNodeDescription value)
{
value = this[key];
return value != null;
}
#endregion
}
}