Class TypeDictionary<T>
A dictionary used to map types to specific object instances of the type.
Implements
Inherited Members
Namespace: Microsoft.XboxStudios.BotBrain
Assembly: BotBrain.Core.dll
Syntax
public class TypeDictionary<T> : IEquatable<TypeDictionary<T>?>, ICollection<KeyValuePair<Type, T>>, IEnumerable<KeyValuePair<Type, T>>, IEnumerable, IDisposable
Type Parameters
Name | Description |
---|---|
T | The base class type. |
Remarks
Subclasses added to the dictionary will replace instances of their base classes.
Properties
View SourceCount
Gets the number of objects contained in the dictionary.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
IsReadOnly
Gets a value indicating whether or not the dictionary is read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
bool |
Keys
Gets a collection containing the types of objects in the dictionary.
Declaration
public ICollection<Type> Keys { get; }
Property Value
Type | Description |
---|---|
ICollection<Type> |
Values
Gets a collection containing the objects in the dictionary.
Declaration
public ICollection<T> Values { get; }
Property Value
Type | Description |
---|---|
ICollection<T> |
Methods
View SourceAdd(KeyValuePair<Type, T>)
Adds a type and object to the dictionary.
Declaration
public void Add(KeyValuePair<Type, T> item)
Parameters
Type | Name | Description |
---|---|---|
KeyValuePair<Type, T> | item | The type and object to add. |
Add(T)
Adds an object to the dictionary.
Declaration
public void Add(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The object to add. |
Clear()
Removes all objects from the dictionary.
Declaration
public void Clear()
Contains(KeyValuePair<Type, T>)
Determines whether the dictionary contains a specific value.
Declaration
public bool Contains(KeyValuePair<Type, T> item)
Parameters
Type | Name | Description |
---|---|---|
KeyValuePair<Type, T> | item | The object to locate. |
Returns
Type | Description |
---|---|
bool | True if the object is found. |
CopyTo(KeyValuePair<Type, T>[], int)
Copies the elements of the dictionary to an array.
Declaration
public void CopyTo(KeyValuePair<Type, T>[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
KeyValuePair<Type, T>[] | array | The array to copy to. |
int | arrayIndex | The index at which copying begins. |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Equals(TypeDictionary<T>?)
Compares this dictionary to another.
Declaration
public bool Equals(TypeDictionary<T>? other)
Parameters
Type | Name | Description |
---|---|---|
TypeDictionary<T> | other | The dictionary to compare to. |
Returns
Type | Description |
---|---|
bool | Whether or not the dictionaries are equal. |
Equals(object?)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current object. |
Returns
Type | Description |
---|---|
bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
View SourceFind(Type, out T)
Finds an object with the given type.
Declaration
public bool Find(Type type, out T value)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
T | value | The object, if found. |
Returns
Type | Description |
---|---|
bool | Whether or not an object was found. |
Find<T2>()
Finds an object with the given type.
Declaration
public T2? Find<T2>() where T2 : class, T
Returns
Type | Description |
---|---|
T2 | The object, if found. |
Type Parameters
Name | Description |
---|---|
T2 | The type. |
GetEnumerator()
Returns an enumerator that iterates through the dictionary.
Declaration
public IEnumerator<KeyValuePair<Type, T>> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<KeyValuePair<Type, T>> | An enumerator. |
GetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the current object. |
Overrides
View SourceRemove(KeyValuePair<Type, T>)
Removes the given object.
Declaration
public bool Remove(KeyValuePair<Type, T> item)
Parameters
Type | Name | Description |
---|---|---|
KeyValuePair<Type, T> | item | The object. |
Returns
Type | Description |
---|---|
bool | Whether or not an object was removed. |
Remove(Type)
Removes objects with the given type.
Declaration
public bool Remove(Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Returns
Type | Description |
---|---|
bool | Whether or not an object was removed. |
Remove<T2>()
Removes objects with the given type.
Declaration
public bool Remove<T2>()
Returns
Type | Description |
---|---|
bool | Whether or not an object was removed. |
Type Parameters
Name | Description |
---|---|
T2 | The type. |
Update(Type, Action<bool, T>?)
Finds an existing object with the given type, or creates a new object if necessary, and then calls the given action.
Declaration
public T Update(Type type, Action<bool, T>? update = null)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Action<bool, T> | update | The action to execute. The first parameter indicates if a new object was created. |
Returns
Type | Description |
---|---|
T | The object. |
Update(Type, Action<T>)
Finds an existing object with the given type, or creates a new object if necessary, and then calls the given action.
Declaration
public T Update(Type type, Action<T> update)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type. |
Action<T> | update | The action to execute. |
Returns
Type | Description |
---|---|
T | The object. |
UpdateOrRemove<T2>(bool, Action<T2>?)
If the value is true, calls AddOrUpdate with the given action, or else calls Remove.
Declaration
public void UpdateOrRemove<T2>(bool value, Action<T2>? update = null) where T2 : class, T, new()
Parameters
Type | Name | Description |
---|---|---|
bool | value | The value. |
Action<T2> | update | The action to execute. |
Type Parameters
Name | Description |
---|---|
T2 | The type to add or remove. |
Update<T2>(Action<T2>?)
Finds an existing object with the given type, or creates a new object if necessary, and then calls the given action.
Declaration
public T2 Update<T2>(Action<T2>? update = null) where T2 : class, T, new()
Parameters
Type | Name | Description |
---|---|---|
Action<T2> | update | The action to execute. |
Returns
Type | Description |
---|---|
T2 | The object. |
Type Parameters
Name | Description |
---|---|
T2 | The type. |
WhereEquals(IEnumerable<KeyValuePair<Type, T>>, Func<KeyValuePair<Type, T>, bool>?)
Compares this dictionary to another enumeration of key-value pairs.
Declaration
public bool WhereEquals(IEnumerable<KeyValuePair<Type, T>> other, Func<KeyValuePair<Type, T>, bool>? predicate)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<KeyValuePair<Type, T>> | other | The enumeration to compare to. |
Func<KeyValuePair<Type, T>, bool> | predicate | The key-value pairs to include in the comparison. |
Returns
Type | Description |
---|---|
bool | Whether or not the key-value pairs are equal. |