Show / Hide Table of Contents

Class TypeDictionary<T>

A dictionary used to map types to specific object instances of the type.

Inheritance
object
TypeDictionary<T>
Implements
IEquatable<TypeDictionary<T>>
ICollection<KeyValuePair<Type, T>>
IEnumerable<KeyValuePair<Type, T>>
IEnumerable
IDisposable
Inherited Members
object.Equals(object, object)
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
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 Source

Count

Gets the number of objects contained in the dictionary.

Declaration
public int Count { get; }
Property Value
Type Description
int
View Source

IsReadOnly

Gets a value indicating whether or not the dictionary is read-only.

Declaration
public bool IsReadOnly { get; }
Property Value
Type Description
bool
View Source

Keys

Gets a collection containing the types of objects in the dictionary.

Declaration
public ICollection<Type> Keys { get; }
Property Value
Type Description
ICollection<Type>
View Source

Values

Gets a collection containing the objects in the dictionary.

Declaration
public ICollection<T> Values { get; }
Property Value
Type Description
ICollection<T>

Methods

View Source

Add(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.

View Source

Add(T)

Adds an object to the dictionary.

Declaration
public void Add(T value)
Parameters
Type Name Description
T value

The object to add.

View Source

Clear()

Removes all objects from the dictionary.

Declaration
public void Clear()
View Source

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.

View Source

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.

View Source

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()
View Source

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.

View Source

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
object.Equals(object)
View Source

Find(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.

View Source

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.

View Source

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.

View Source

GetHashCode()

Serves as the default hash function.

Declaration
public override int GetHashCode()
Returns
Type Description
int

A hash code for the current object.

Overrides
object.GetHashCode()
View Source

Remove(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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

Implements

IEquatable<T>
ICollection<T>
IEnumerable<T>
IEnumerable
IDisposable

Extension Methods

ICollectionExtensions.GetNearestIndex<T>(ICollection<T>, int)
ICollectionExtensions.AddRange<T>(ICollection<T>, IEnumerable<T>)
ICollectionExtensions.ForEach<T>(ICollection<T>, Action<T>)
ICollectionExtensions.SetRange<T>(ICollection<T>, IEnumerable<T>)
IEnumerableExtensions.WithoutLast<T>(IEnumerable<T>)
  • View Source
In this article
Back to top Generated by DocFX