Show / Hide Table of Contents

Class TypeDictionary<T>

An implementation of the ITypeDictionary<T> interface. This implementation supports multithreaded access.

Inheritance
System.Object
TypeDictionary<T>
Implements
ITypeDictionary<T>
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Type, T>>
System.Collections.IEnumerable
ICloneable
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: SpiceSharp.General
Assembly: SpiceSharp.dll
Syntax
public class TypeDictionary<T> : ITypeDictionary<T>, IEnumerable<KeyValuePair<Type, T>>, IEnumerable, ICloneable
Type Parameters
Name Description
T

The base type.

Constructors

TypeDictionary()

Initializes a new instance of the TypeDictionary<T> class.

Declaration
public TypeDictionary()

Properties

Count

Gets the number of elements contained in the ITypeDictionary<T>.

Declaration
public int Count { get; }
Property Value
Type Description
System.Int32

The count.

Item[Type]

Gets the value with the specified key.

Declaration
public T this[Type key] { get; }
Parameters
Type Name Description
System.Type key

The key.

Property Value
Type Description
T

The key type.

Exceptions
Type Condition
System.ArgumentNullException

Thrown if key is null.

System.Collections.Generic.KeyNotFoundException

Thrown if key was not found.

AmbiguousTypeException

If there are multiple values of type key.

Keys

Gets the keys.

Declaration
public IEnumerable<Type> Keys { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<System.Type>

The keys.

Values

Gets the values.

Declaration
public IEnumerable<T> Values { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<T>

The values.

Methods

Add<V>(V)

Adds the specified value to the dictionary.

Declaration
public void Add<V>(V value)
    where V : T
Parameters
Type Name Description
V value

The value.

Type Parameters
Name Description
V

The value type.

Exceptions
Type Condition
System.ArgumentNullException

Thrown if value is null.

System.ArgumentException

Thrown if a value of type V was already added.

Clear()

Removes all items from the TypeDictionary<T>.

Declaration
public void Clear()

Clone()

Clones the instance.

Declaration
protected virtual ICloneable Clone()
Returns
Type Description
ICloneable

The cloned instance.

ContainsKey(Type)

Determines whether the dictionary contains one or more values of the specified type.

Declaration
public bool ContainsKey(Type key)
Parameters
Type Name Description
System.Type key

The key.

Returns
Type Description
System.Boolean

true if the dictionary contains one ore more values of the specified type; otherwise, false.

Exceptions
Type Condition
System.ArgumentNullException

Thrown if key is null.

ContainsValue(T)

Determines whether the dictionary contains the specified value.

Declaration
public bool ContainsValue(T value)
Parameters
Type Name Description
T value

The value.

Returns
Type Description
System.Boolean

true if the dictionary contains the specified value; otherwise, false.

Exceptions
Type Condition
System.ArgumentNullException

Thrown if value is null.

CopyFrom(ICloneable)

Copies the contents of one interface to this one.

Declaration
protected virtual void CopyFrom(ICloneable source)
Parameters
Type Name Description
ICloneable source

The source parameter.

GetAllValues<TResult>()

Gets all strongly typed values from the dictionary.

Declaration
public IEnumerable<TResult> GetAllValues<TResult>()
    where TResult : T
Returns
Type Description
System.Collections.Generic.IEnumerable<TResult>

The results.

Type Parameters
Name Description
TResult

The type of the result.

GetEnumerator()

Returns an enumerator that iterates through the collection.

Declaration
public IEnumerator<KeyValuePair<Type, T>> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<System.Type, T>>

An enumerator that can be used to iterate through the collection.

GetValue<TResult>()

Gets the strongly typed value from the dictionary.

Declaration
public TResult GetValue<TResult>()
    where TResult : T
Returns
Type Description
TResult

The result.

Type Parameters
Name Description
TResult

The type of the result.

Exceptions
Type Condition
TypeNotFoundException

Thrown if a value of type TResult could not be found.

AmbiguousTypeException

If there are multiple values of type TResult.

Remove(T)

Removes the specified value.

Declaration
public bool Remove(T value)
Parameters
Type Name Description
T value

The value.

Returns
Type Description
System.Boolean

true if the value was removed; otherwise false.

Exceptions
Type Condition
System.ArgumentNullException

Thrown if value is null.

Remove(Type)

Removes the value of the specified type from the dictionary.

Declaration
public bool Remove(Type key)
Parameters
Type Name Description
System.Type key

The key.

Returns
Type Description
System.Boolean

true if the value has been removed succesfully; otherwise false.

Exceptions
Type Condition
System.ArgumentNullException

Thrown if key is null.

TryGetValue(Type, out T)

Tries to get a value from the dictionary.

Declaration
public bool TryGetValue(Type key, out T value)
Parameters
Type Name Description
System.Type key

The key type.

T value

The value.

Returns
Type Description
System.Boolean

true if the value was resolved; otherwise false.

Exceptions
Type Condition
AmbiguousTypeException

If there are multiple values of type key.

TryGetValue<TResult>(out TResult)

Tries to get a strongly typed value from the dictionary.

Declaration
public bool TryGetValue<TResult>(out TResult value)
    where TResult : T
Parameters
Type Name Description
TResult value

The value.

Returns
Type Description
System.Boolean

true if the specified key contains the type; otherwise false.

Type Parameters
Name Description
TResult

The type of the result.

Exceptions
Type Condition
AmbiguousTypeException

If the value could not be uniquely determined.

Explicit Interface Implementations

ICloneable.Clone()

Declaration
ICloneable ICloneable.Clone()
Returns
Type Description
ICloneable

ICloneable.CopyFrom(ICloneable)

Declaration
void ICloneable.CopyFrom(ICloneable source)
Parameters
Type Name Description
ICloneable source

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator

An System.Collections.IEnumerator object that can be used to iterate through the collection.

Implements

ITypeDictionary<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
ICloneable

Extension Methods

Utility.ThrowIfNull<T>(T, String)

See Also

ITypeDictionary<T>
Back to top Generated by DocFX