Edit

Share via


ContextStack.Item[] Property

Definition

Gets or sets the object on the stack at the specified level.

Overloads

Item[Int32]

Gets the object on the stack at the specified level.

Item[Type]

Gets the first object on the stack that inherits from or implements the specified type.

Item[Int32]

Source:
ContextStack.cs
Source:
ContextStack.cs
Source:
ContextStack.cs

Gets the object on the stack at the specified level.

public object? this[int level] { get; }
public object this[int level] { get; }

Parameters

level
Int32

The level of the object to retrieve on the stack. Level 0 is the top of the stack, level 1 is the next down, and so on. This level must be 0 or greater. If level is greater than the number of levels on the stack, it returns null.

Property Value

The object on the stack at the specified level, or null if no object exists at that level.

Exceptions

level is less than 0.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Item[Type]

Source:
ContextStack.cs
Source:
ContextStack.cs
Source:
ContextStack.cs

Gets the first object on the stack that inherits from or implements the specified type.

public object this[Type type] { get; }

Parameters

type
Type

A type to retrieve from the context stack.

Property Value

The first object on the stack that inherits from or implements the specified type, or null if no object on the stack implements the type.

Exceptions

type is null.

Remarks

A check is made on each level of the stack, searching for an object that implements or inherits type. If a match is found, it is returned.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1