Share via


WebTestContext.TryGetValue Method

Gets the value associated with the specified key.

Namespace:  Microsoft.VisualStudio.TestTools.WebTesting
Assembly:  Microsoft.VisualStudio.QualityTools.WebTestFramework (in Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)

Syntax

'Declaration
Public Function TryGetValue ( _
    key As String, _
    <OutAttribute> ByRef value As Object _
) As Boolean
public bool TryGetValue(
    string key,
    out Object value
)
public:
virtual bool TryGetValue(
    String^ key, 
    [OutAttribute] Object^% value
) sealed
abstract TryGetValue : 
        key:string * 
        value:Object byref -> bool  
override TryGetValue : 
        key:string * 
        value:Object byref -> bool
public final function TryGetValue(
    key : String, 
    value : Object
) : boolean

Parameters

  • key
    Type: String

    The key to find.

  • value
    Type: Object%

    The referenced object that retrieves the value of the key, if it is found; otherwise, it retrieves the default value for the type of the value parameter. This parameter can be passed uninitialized.

Return Value

Type: Boolean
true if it contains an element with the specified key; otherwise, false.

Implements

IDictionary.TryGetValue(UTP, UTP)

Exceptions

Exception Condition
ArgumentNullException

key is nulla null reference (Nothing in Visual Basic).

Remarks

Context defined by environmental variables or a load test will override the item returned by this property. So if a Web performance test is running in a load test that contains a context called "myContext", a call to MyWebTestContext.TryGetValue("myContext", MyObject) will return the value for the LoadTestContext.Item("myContext", MyObject).

This is the most efficient way to try to retrieve values if several tried keys are not in the dictionary. This method combines the functionality of the ContainsKey method and the Item property.

If the key is not found, the outvalue parameter receives the appropriate default value: zero for integer types, false for Boolean types, and nulla null reference (Nothing in Visual Basic) for reference types.

.NET Framework Security

See Also

Reference

WebTestContext Class

Microsoft.VisualStudio.TestTools.WebTesting Namespace