Class McpServerPrimitiveCollection<T>
- Namespace
- ModelContextProtocol.Server
- Assembly
- ModelContextProtocol.dll
Provides a thread-safe collection of T
instances, indexed by their names.
public class McpServerPrimitiveCollection<T> : ICollection<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable where T : IMcpServerPrimitive
Type Parameters
T
Specifies the type of primitive stored in the collection.
- Inheritance
-
McpServerPrimitiveCollection<T>
- Implements
-
ICollection<T>IEnumerable<T>
- Inherited Members
Constructors
McpServerPrimitiveCollection()
Initializes a new instance of the McpServerPrimitiveCollection<T> class.
public McpServerPrimitiveCollection()
Properties
Count
Gets the number of primitives in the collection.
public int Count { get; }
Property Value
IsEmpty
Gets whether there are any primitives in the collection.
public bool IsEmpty { get; }
Property Value
this[string]
Gets the T
with the specified name
from the collection.
public T this[string name] { get; }
Parameters
name
stringThe name of the primitive to retrieve.
Property Value
- T
The
T
with the specified name.
Exceptions
- ArgumentNullException
name
is null.- KeyNotFoundException
An primitive with the specified name does not exist in the collection.
PrimitiveNames
Gets the names of all of the primitives in the collection.
public virtual ICollection<string> PrimitiveNames { get; }
Property Value
Methods
Add(T)
Adds the specified T
to the collection.
public void Add(T primitive)
Parameters
primitive
TThe primitive to be added.
Exceptions
- ArgumentNullException
primitive
is null.- ArgumentException
A primitive with the same name as
primitive
already exists in the collection.
Clear()
Clears all primitives from the collection.
public virtual void Clear()
Contains(T)
Checks if a specific primitive is present in the collection of primitives.
public virtual bool Contains(T primitive)
Parameters
primitive
TThe primitive to search for in the collection.
Returns
Exceptions
- ArgumentNullException
primitive
is null.
CopyTo(T[], int)
Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.
public virtual void CopyTo(T[] array, int arrayIndex)
Parameters
array
T[]The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.
arrayIndex
intThe zero-based index in
array
at which copying begins.
Exceptions
- ArgumentNullException
array
is null.- ArgumentOutOfRangeException
arrayIndex
is less than 0.- ArgumentException
The number of elements in the source ICollection<T> is greater than the available space from
arrayIndex
to the end of the destinationarray
.
GetEnumerator()
public virtual IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
RaiseChanged()
Raises Changed if there are registered handlers.
protected void RaiseChanged()
Remove(T)
Removes the specified primitivefrom the collection.
public virtual bool Remove(T primitive)
Parameters
primitive
TThe primitive to be removed from the collection.
Returns
- bool
true if the primitive was found in the collection and removed; otherwise, false if it couldn't be found.
Exceptions
- ArgumentNullException
primitive
is null.
ToArray()
Creates an array containing all of the primitives in the collection.
public virtual T[] ToArray()
Returns
- T[]
An array containing all of the primitives in the collection.
TryAdd(T)
Adds the specified T
to the collection.
public virtual bool TryAdd(T primitive)
Parameters
primitive
TThe primitive to be added.
Returns
Exceptions
- ArgumentNullException
primitive
is null.
TryGetPrimitive(string, out T?)
Attempts to get the primitive with the specified name from the collection.
public virtual bool TryGetPrimitive(string name, out T? primitive)
Parameters
name
stringThe name of the primitive to retrieve.
primitive
TThe primitive, if found; otherwise, null.
Returns
- bool
true if the primitive was found in the collection and return; otherwise, false if it couldn't be found.
Exceptions
- ArgumentNullException
name
is null.
Events
Changed
Occurs when the collection is changed.
public event EventHandler? Changed
Event Type
Remarks
By default, this is raised when a primitive is added or removed. However, a derived implementation may raise this event for other reasons, such as when a primitive is modified.