Skip to content

TryGetItem Method ​

Definition ​

  • Namespace: JASE.Extensions
  • Assembly: JASE.Web.dll

bool TryGetItem(HttpContext context, string key, out T result) ​

csharp
bool TryGetItem(HttpContext context, string key, out T result)

Attempts to retrieve a value from Items and cast it to the requested type.

Type parameters ​

NameDescription
TThe expected type of the item value.

Parameters ​

NameDescription
contextThe current HTTP context whose Items collection will be searched.
keyThe item key to look up.
resultWhen this method returns , contains the value associated with key cast to T. Otherwise, contains the default value for T.

Returns ​

if an item with the specified key exists and can be cast to T; otherwise, .

Remarks ​

This method does not throw if the key is missing or if the stored value is not of the requested type. In those cases, it returns and sets result to the default value.