Struct UserDataStorage
Provides access to user data associated with the object.
Inherited Members
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public readonly ref struct UserDataStorage
Remarks
This is by-ref struct because user data should have the same lifetime as its owner.
Properties
| Edit this page View SourceIsValid
Gets a value indicating that this storage is valid.
Declaration
public bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
| Edit this page View SourceCapture()
Extracts a copy of all custom data in this storage.
Declaration
public IReadOnlyDictionary<string, object> Capture()
Returns
| Type | Description |
|---|---|
| IReadOnlyDictionary<string, object> | The copy of all custom data. |
Remarks
This method is useful for debugging purposes to observe the data associated with arbitrary object.
CopyTo(object)
Replaces user data of the object with the copy of the current one.
Declaration
public void CopyTo(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object which user data has to be replaced with the copy of the current one. |
Equals(object?)
Determines whether this storage is attached to the given object.
Declaration
public override bool Equals(object? other)
Parameters
| Type | Name | Description |
|---|---|---|
| object | other | Other object to check. |
Returns
| Type | Description |
|---|---|
| bool | true, if this storage is attached to |
Overrides
| Edit this page View SourceGetHashCode()
Computes identity hash code for this storage.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | The identity hash code for this storage. |
Overrides
| Edit this page View SourceGetOrSet<TValue>(UserDataSlot<TValue>)
Gets existing user data or creates a new data and return it.
Declaration
public TValue GetOrSet<TValue>(UserDataSlot<TValue> slot) where TValue : notnull, new()
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
Returns
| Type | Description |
|---|---|
| TValue | The data associated with the slot. |
Type Parameters
| Name | Description |
|---|---|
| TValue | The type of user data associated with arbitrary object. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
GetOrSet<TValue>(UserDataSlot<TValue>, delegate*<TValue>)
Gets existing user data or creates a new data and return it.
Declaration
[CLSCompliant(false)]
public TValue GetOrSet<TValue>(UserDataSlot<TValue> slot, delegate*<TValue> valueFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
| delegate*<TValue> | valueFactory | The value supplier which is called when no user data exists. |
Returns
| Type | Description |
|---|---|
| TValue | The data associated with the slot. |
Type Parameters
| Name | Description |
|---|---|
| TValue | The type of user data associated with arbitrary object. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
GetOrSet<TValue>(UserDataSlot<TValue>, Func<TValue>)
Gets existing user data or creates a new data and return it.
Declaration
public TValue GetOrSet<TValue>(UserDataSlot<TValue> slot, Func<TValue> valueFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
| Func<TValue> | valueFactory | The value supplier which is called when no user data exists. |
Returns
| Type | Description |
|---|---|
| TValue | The data associated with the slot. |
Type Parameters
| Name | Description |
|---|---|
| TValue | The type of user data associated with arbitrary object. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
GetOrSet<TBase, T>(UserDataSlot<TBase>)
Gets existing user data or creates a new data and return it.
Declaration
public TBase GetOrSet<TBase, T>(UserDataSlot<TBase> slot) where T : class, TBase, new()
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TBase> | slot | The slot identifying user data. |
Returns
| Type | Description |
|---|---|
| TBase | The data associated with the slot. |
Type Parameters
| Name | Description |
|---|---|
| TBase | The type of user data associated with arbitrary object. |
| T | The derived type with public parameterless constructor. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
GetOrSet<TValue, TFactory>(UserDataSlot<TValue>, TFactory)
Gets existing user data or creates a new data and return it.
Declaration
public TValue GetOrSet<TValue, TFactory>(UserDataSlot<TValue> slot, TFactory valueFactory) where TFactory : struct, ISupplier<TValue>
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
| TFactory | valueFactory | The value supplier which is called when no user data exists. |
Returns
| Type | Description |
|---|---|
| TValue | The data associated with the slot. |
Type Parameters
| Name | Description |
|---|---|
| TValue | The type of user data associated with arbitrary object. |
| TFactory | The type of the factory. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
GetOrSet<T, TValue>(UserDataSlot<TValue>, T, delegate*<T, TValue>)
Gets existing user data or creates a new data and return it.
Declaration
[CLSCompliant(false)]
public TValue GetOrSet<T, TValue>(UserDataSlot<TValue> slot, T arg, delegate*<T, TValue> valueFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
| T | arg | The argument to be passed into factory. |
| delegate*<T, TValue> | valueFactory | The value supplier which is called when no user data exists. |
Returns
| Type | Description |
|---|---|
| TValue | The data associated with the slot. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the argument to be passed into factory. |
| TValue | The type of user data associated with arbitrary object. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
GetOrSet<T, TValue>(UserDataSlot<TValue>, T, Func<T, TValue>)
Gets existing user data or creates a new data and return it.
Declaration
public TValue GetOrSet<T, TValue>(UserDataSlot<TValue> slot, T arg, Func<T, TValue> valueFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
| T | arg | The argument to be passed into factory. |
| Func<T, TValue> | valueFactory | The value supplier which is called when no user data exists. |
Returns
| Type | Description |
|---|---|
| TValue | The data associated with the slot. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the argument to be passed into factory. |
| TValue | The type of user data associated with arbitrary object. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
GetOrSet<T1, T2, TValue>(UserDataSlot<TValue>, T1, T2, delegate*<T1, T2, TValue>)
Gets existing user data or creates a new data and return it.
Declaration
[CLSCompliant(false)]
public TValue GetOrSet<T1, T2, TValue>(UserDataSlot<TValue> slot, T1 arg1, T2 arg2, delegate*<T1, T2, TValue> valueFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
| T1 | arg1 | The first argument to be passed into factory. |
| T2 | arg2 | The second argument to be passed into factory. |
| delegate*<T1, T2, TValue> | valueFactory | The value supplier which is called when no user data exists. |
Returns
| Type | Description |
|---|---|
| TValue | The data associated with the slot. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first argument to be passed into factory. |
| T2 | The type of the second argument to be passed into factory. |
| TValue | The type of user data associated with arbitrary object. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
GetOrSet<T1, T2, TValue>(UserDataSlot<TValue>, T1, T2, Func<T1, T2, TValue>)
Gets existing user data or creates a new data and return it.
Declaration
public TValue GetOrSet<T1, T2, TValue>(UserDataSlot<TValue> slot, T1 arg1, T2 arg2, Func<T1, T2, TValue> valueFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
| T1 | arg1 | The first argument to be passed into factory. |
| T2 | arg2 | The second argument to be passed into factory. |
| Func<T1, T2, TValue> | valueFactory | The value supplier which is called when no user data exists. |
Returns
| Type | Description |
|---|---|
| TValue | The data associated with the slot. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first argument to be passed into factory. |
| T2 | The type of the second argument to be passed into factory. |
| TValue | The type of user data associated with arbitrary object. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
Get<TValue>(UserDataSlot<TValue>)
Gets user data.
Declaration
public TValue? Get<TValue>(UserDataSlot<TValue> slot)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
Returns
| Type | Description |
|---|---|
| TValue | User data; or |
Type Parameters
| Name | Description |
|---|---|
| TValue | Type of data. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
Get<TValue>(UserDataSlot<TValue>, TValue?)
Gets user data.
Declaration
public TValue? Get<TValue>(UserDataSlot<TValue> slot, TValue? defaultValue)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
| TValue | defaultValue | Default value to be returned if no user data contained in this collection. |
Returns
| Type | Description |
|---|---|
| TValue | User data. |
Type Parameters
| Name | Description |
|---|---|
| TValue | Type of data. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
Remove<TValue>(UserDataSlot<TValue>)
Removes user data slot.
Declaration
public bool Remove<TValue>(UserDataSlot<TValue> slot)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
Returns
| Type | Description |
|---|---|
| bool | true, if data is removed from this collection. |
Type Parameters
| Name | Description |
|---|---|
| TValue | The type of user data. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
Remove<TValue>(UserDataSlot<TValue>, out TValue)
Removes user data slot.
Declaration
public bool Remove<TValue>(UserDataSlot<TValue> slot, out TValue userData)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
| TValue | userData | Remove user data. |
Returns
| Type | Description |
|---|---|
| bool | true, if data is removed from this collection. |
Type Parameters
| Name | Description |
|---|---|
| TValue | The type of user data. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
Set<TValue>(UserDataSlot<TValue>, TValue)
Sets user data.
Declaration
public void Set<TValue>(UserDataSlot<TValue> slot, TValue userData)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
| TValue | userData | User data to be saved in this collection. |
Type Parameters
| Name | Description |
|---|---|
| TValue | Type of data. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
ToString()
Returns textual representation of this storage.
Declaration
public override string? ToString()
Returns
| Type | Description |
|---|---|
| string | The textual representation of this storage. |
Overrides
| Edit this page View SourceTryGet<TValue>(UserDataSlot<TValue>, out TValue)
Tries to get user data.
Declaration
public bool TryGet<TValue>(UserDataSlot<TValue> slot, out TValue userData)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataSlot<TValue> | slot | The slot identifying user data. |
| TValue | userData | User data. |
Returns
| Type | Description |
|---|---|
| bool | true, if user data slot exists in this collection. |
Type Parameters
| Name | Description |
|---|---|
| TValue | Type of data. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
Operators
| Edit this page View Sourceoperator ==(UserDataStorage, UserDataStorage)
Determines whether two stores are for the same object.
Declaration
public static bool operator ==(UserDataStorage first, UserDataStorage second)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataStorage | first | The first storage to compare. |
| UserDataStorage | second | The second storage to compare. |
Returns
| Type | Description |
|---|---|
| bool | true, if two stores are for the same object; otherwise, false. |
operator !=(UserDataStorage, UserDataStorage)
Determines whether two stores are not for the same object.
Declaration
public static bool operator !=(UserDataStorage first, UserDataStorage second)
Parameters
| Type | Name | Description |
|---|---|---|
| UserDataStorage | first | The first storage to compare. |
| UserDataStorage | second | The second storage to compare. |
Returns
| Type | Description |
|---|---|
| bool | true, if two stores are not for the same object; otherwise, false. |