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)

public bool TryGetValue (
	string key,
	out Object value
)
public final boolean TryGetValue (
	String key, 
	/** @attribute OutAttribute() */ /** @ref */ Object value
)
JScript does not support passing value-type arguments by reference.

Parameters

key

The key to find.

value

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

Return Value

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

Exception typeCondition

ArgumentNullException

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

Context defined by environmental variables or a load test will override the item returned by this property. So if a Web 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 get 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, then the outvalue parameter gets the appropriate default value: zero for integer types, false for Boolean types, and a null reference (Nothing in Visual Basic) for reference types.

Show: