Partager via


IExpressionEval::CreateEvalContext Method

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

Use this method to create a new ExprEvalContext object and place it into the context cache. This allows evaluation of multiple expressions against the same set of profile objects in the most efficient manner possible.

HRESULT IExpressionEval::CreateEvalContext(
  IDictionary* pDictObjs,
  IExprEvalContext** ppContext
);
Function CreateEvalContext(
    pDictObjs As Object
) As Object

Parameters

  • pDictObjs
    [C++]

    [in] A pointer to the IDictionary interface of a Dictionary object that contains the set of profiles to be cached.

    [Visual Basic]

    A Dictionary object that contains the set of profiles to be cached.

  • ppContext
    [C++]

    [out, retval] The address of the pointer to the IExprEvalContext interface of the newly created ExprEvalContext object.

Return Value

[C++]

This method returns an HRESULT indicating whether it completed successfully. See the Error Values section for more details.

[Visual Basic]

If this method completes successfully, it returns the newly created ExprEvalContext object.

Error Values

[C++]

This method returns S_OK (0x00000000) to indicate success and standard COM HRESULT error values to indicate failure. For more information about standard COM errors, see Standard COM Errors. Additional information may be available using the global Err object, which can be accessed using the API function GetErrorInfo. In particular, the GetDescription method of the IErrorInfo interface may return a text description of the error.

[Visual Basic]

This method sets the Number property of the global Err object to S_OK (&H00000000) to indicate success and to standard COM error values to indicate failure. For more information about standard COM errors, see Standard COM Errors. Additional information may be available using the global Err object. In particular, the Description property may contain a text description of the error.

Remarks

The CreateEvalContext method creates an ExprEvalContext object that uniquely identifies a new evaluation context and stores the object in the context cache. Use the EvalInContext method to evaluate multiple expressions within the context defined by the ExprEvalContext object. This process is more efficient than using the Eval method which generates and destroys a new context for each expression evaluated.

A context is a set of profiles containing data to evaluate expressions against. Profiles may be ProfileObject objects, Dictionary objects, or other objects that support property access through the IDispatch interface. Initially only references to the profile objects are held in the context cache. During evaluation, when property values are read from the profiles, the property values may themselves be held in the cache for faster access during subsequent evaluations.

The ppContext parameter contains valid data only if the method completes successfully.

Warning

The state of the profile objects should not be externally changed during the lifetime of the ExprEvalContext object; doing so leads to non-deterministic evaluation results.

Example

' dictUser1, dictAddress1, & dictProfiles are Dictionary objects.
' Create 2 profiles.

dictUser1.firstName = "Joe"
dictUser1.lastName = "User"
dictAddress1.city = "Somewhere"
dictAddress1.state = "WA"

' Add the profiles to the context Dictionary.

dictProfiles.User = dictUser1
dictProfiles.Address = dictAddress1

' Create the evaluation context.

oExprEvalContext = oExpressionEval.CreateEvalContext(dictProfiles)

See Also

Other Resources

ExpressionEval Object

IExpressionEval::EvalInContext Method