Show / Hide Table of Contents

Struct UserDataStorage

Provides access to user data associated with the object.

Inherited Members
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
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 Source

IsValid

Gets a value indicating that this storage is valid.

Declaration
public bool IsValid { get; }
Property Value
Type Description
bool

Methods

| Edit this page View Source

Capture()

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.

| Edit this page View Source

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.

| Edit this page View Source

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 other object; otherwise, false.

Overrides
ValueType.Equals(object)
| Edit this page View Source

GetHashCode()

Computes identity hash code for this storage.

Declaration
public override int GetHashCode()
Returns
Type Description
int

The identity hash code for this storage.

Overrides
ValueType.GetHashCode()
| Edit this page View Source

GetOrSet<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

slot is not allocated.

| Edit this page View Source

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

slot is not allocated.

| Edit this page View Source

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

slot is not allocated.

| Edit this page View Source

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

slot is not allocated.

| Edit this page View Source

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

slot is not allocated.

| Edit this page View Source

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

slot is not allocated.

| Edit this page View Source

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

slot is not allocated.

| Edit this page View Source

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

slot is not allocated.

| Edit this page View Source

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

slot is not allocated.

| Edit this page View Source

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 default(V) if there is no user data associated with slot.

Type Parameters
Name Description
TValue

Type of data.

Exceptions
Type Condition
ArgumentException

slot is not allocated.

| Edit this page View Source

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

slot is not allocated.

| Edit this page View Source

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

slot is not allocated.

| Edit this page View Source

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

slot is not allocated.

| Edit this page View Source

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

slot is not allocated.

| Edit this page View Source

ToString()

Returns textual representation of this storage.

Declaration
public override string? ToString()
Returns
Type Description
string

The textual representation of this storage.

Overrides
ValueType.ToString()
| Edit this page View Source

TryGet<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

slot is not allocated.

Operators

| Edit this page View Source

operator ==(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.

| Edit this page View Source

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.

  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾