Class AnyMap
- Namespace
- MonkeyLoader
- Assembly
- MonkeyLoader.dll
Represents a type safe dictionary mapping Types to objects of the type.
public sealed class AnyMap
- Inheritance
-
AnyMap
- Inherited Members
Properties
Keys
Gets all Types that have a set value in this AnyMap.
public IEnumerable<Type> Keys { get; }
Property Value
Methods
Add<T>(T)
Adds the given value for type T to this AnyMap.
public void Add<T>(T value)
Parameters
valueTThe value to associate with the type.
Type Parameters
TThe type of the value.
Clear()
Removes all keys and values of this AnyMap.
public void Clear()
ContainsKey<T>()
Determines whether this AnyMap contains a value for type T.
public bool ContainsKey<T>()
Returns
- bool
trueif there is a value for the type; otherwise,false.
Type Parameters
TThe type of the value.
GetCastableValues<T>()
Gets all non-null values that are castable to T in this AnyMap.
public IEnumerable<T> GetCastableValues<T>()
Returns
- IEnumerable<T>
All non-
nullvalues that are castable toT.
Type Parameters
TThe common type of the values.
GetOrCreateValue<T>()
Gets the value associated with the type T in this AnyMap,
or creates and associates a new instance of T using its parameterless constructor.
public T GetOrCreateValue<T>() where T : new()
Returns
- T
The value associated with the type or the newly created instance.
Type Parameters
TThe type of the value.
GetOrCreateValue<T>(Func<T>)
Gets the value associated with the type T in this AnyMap,
or creates and associates the value returned by the given valueFactory.
public T GetOrCreateValue<T>(Func<T> valueFactory)
Parameters
valueFactoryFunc<T>A factory method that creates a value when there is none yet.
Returns
- T
The value associated with the type or the newly created instance.
Type Parameters
TThe type of the value.
GetValue(Type)
Gets the value associated with the given type in this AnyMap.
public object GetValue(Type type)
Parameters
typeType
Returns
- object
The value associated with the given type.
Exceptions
- KeyNotFoundException
When there is no value for the
type.
GetValue<T>()
Gets the value associated with the type T in this AnyMap.
public T GetValue<T>()
Returns
- T
The value associated with the type.
Type Parameters
TThe type of the value.
Exceptions
- KeyNotFoundException
When there is no value for
T.
GetValue<T>(Type)
Gets the value associated with the given type in this AnyMap.
public T GetValue<T>(Type type)
Parameters
typeType
Returns
- T
The value associated with the given type.
Type Parameters
TThe type of the value. Only used for casting, not access.
Exceptions
- KeyNotFoundException
When there is no value for the
type.
Remove(Type)
Removes the value associated with the given type in this AnyMap.
public void Remove(Type type)
Parameters
typeTypeThe type of the value.
Remove<T>()
Removes the value associated with the type T in this AnyMap.
public void Remove<T>()
Type Parameters
TThe type of the value.
SetValue(Type, object?)
Sets the given value for the given type in this AnyMap.
public void SetValue(Type type, object? value)
Parameters
Exceptions
- InvalidCastException
When the given value is not assignable to the given type.
SetValue<T>(T)
Sets the given value for type T in this AnyMap.
public void SetValue<T>(T value)
Parameters
valueTThe new value to associate with the type.
Type Parameters
TThe type of the value.
TryGetValue(Type, out object?)
Tries to get the value associated with the given type in this AnyMap.
public bool TryGetValue(Type type, out object? value)
Parameters
Returns
- bool
trueif the value was found; otherwise,false.
TryGetValue<T>(Type, out T?)
Tries to get the value associated with the given type in this AnyMap.
public bool TryGetValue<T>(Type type, out T? value)
Parameters
typeTypeThe type of the value.
valueTThe value if it was found; otherwise,
default(.T)
Returns
- bool
trueif the value was found; otherwise,false.
Type Parameters
TThe type of the value. Only used for casting, not access.
TryGetValue<T>(out T?)
Tries to get the value associated with the type T in this AnyMap.
public bool TryGetValue<T>(out T? value)
Parameters
valueTThe value if it was found; otherwise,
default(.T)
Returns
- bool
trueif the value was found; otherwise,false.
Type Parameters
TThe type of the value.