[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Enables compilers to dynamically attach object fields to objects.
Namespace:
System.Runtime.CompilerServices
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
<ComVisibleAttribute(False)> _
Public NotInheritable Class ConditionalWeakTable(Of TKey As Class, TValue As Class)
Dim instance As ConditionalWeakTable(Of TKey, TValue)
[ComVisibleAttribute(false)]
public sealed class ConditionalWeakTable<TKey, TValue>
where TKey : class
where TValue : class
[ComVisibleAttribute(false)]
generic<typename TKey, typename TValue>
where TKey : ref class
where TValue : ref class
public ref class ConditionalWeakTable sealed
[<SealedAttribute>]
[<ComVisibleAttribute(false)>]
type ConditionalWeakTable<'TKey, 'TValue when 'TKey : not struct when 'TValue : not struct> = class end
Type Parameters
- TKey
The generic key type.
- TValue
The generic value type.
Language compilers can expose the ability to attach arbitrary properties to managed objects at run time. The ConditionalWeakTable<(Of <(TKey, TValue>)>) class provides this support as a dictionary whose keys are the instanced objects and whose values are the properties.
ConditionalWeakTable<(Of <(TKey, TValue>)>) has the following characteristics:
It is referred to as a table, rather than a dictionary, because unlike a regular dictionary, ConditionalWeakTable<(Of <(TKey, TValue>)>) does not persist keys. In addition, ConditionalWeakTable<(Of <(TKey, TValue>)>) does not implement the IDictionary<(Of <(TKey, TValue>)>) interface, and, therefore, does not implement all the methods that a dictionary should have.
Inserting a key and value into the table will not cause the key to persist even if the key can be reached directly from normal program code. As soon as the key is detached from a managed object, ConditionalWeakTable<(Of <(TKey, TValue>)>) automatically removes the key/value entry.
It mirrors the form and functionality of the IDictionary<(Of <(TKey, TValue>)>) interface. However, it is also thread safe and requires no additional locking by callers.
It is not intended to be a general-purpose collection, and does not implement IDictionary<(Of <(TKey, TValue>)>) or expose the full IDictionary<(Of <(TKey, TValue>)>) public surface area.
Equality is defined to be Object..::.ReferenceEquals.
It does not invoke Object..::.GetHashCode overrides.
Note |
|---|
ConditionalWeakTable<(Of <(TKey, TValue>)>) operations detect internal data corruption. If the table is corrupt, table operations raise an InvalidOperationException exception. This exception is not expected to occur, and there is no need to catch it in application code. |
System..::.Object
System.Runtime.CompilerServices..::.ConditionalWeakTable<(Of <(TKey, TValue>)>)
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 4
.NET Framework Client Profile
Supported in: 4
Reference