ClearScript Library
ClearScript Library
ClearScript Library Reference
Microsoft.ClearScript
ScriptEngine Class
ScriptEngine Methods
Evaluate Method
Evaluate(String) Method
Evaluate(DocumentInfo, String) Method
Evaluate(String, String) Method
Evaluate(String, Boolean, String) Method

# ScriptEngineEvaluate(String, Boolean, String) Method

Evaluates script code with an associated document name, optionally discarding the document after execution.
Namespace: Microsoft.ClearScript
Assembly: ClearScript.Core (in ClearScript.Core.dll) Version: 7.5.0
Syntax
C#
VB
C++
F#
Copy

    public Object Evaluate(
    	string documentName,
    	bool discard,
    	string code
    )

    Public Function Evaluate (
    	documentName As String,
    	discard As Boolean,
    	code As String
    ) As Object

    public:
    virtual Object^ Evaluate(
    	String^ documentName,
    	bool discard,
    	String^ code
    ) sealed

    abstract Evaluate :
            documentName : string *
            discard : bool *
            code : string -> Object
    override Evaluate :
            documentName : string *
            discard : bool *
            code : string -> Object

#### Parameters

documentName String
  A document name for the script code. Currently, this name is used only as a label in presentation contexts such as debugger user interfaces.
discard Boolean
  True to discard the script document after execution, false otherwise.
code String
  The script code to evaluate.

#### Return Value

Object
The result value.

#### Implements

IScriptEngineEvaluate(String, Boolean, String)
Remarks

In some script languages the distinction between statements and expressions is significant but ambiguous for certain syntactic elements. This method always interprets the specified script code as an expression.

If a debugger is attached, it will present the specified script code to the user as a document with the specified name. Discarding this document removes it from view but has no effect on the script engine. Only Windows Script engines honor discard.

The following table summarizes the types of result values that script code can return.

Type | Returned As | Remarks
--- | --- | ---
String | System.String | N/A
Boolean | System.Boolean | N/A
Number | System.Int32 or System.Double | Other numeric types are possible. The exact conversions between script and .NET numeric types are defined by the script engine.
Null Reference | null | N/A
Undefined | Undefined | This represents JavaScript's undefined, VBScript's Empty, etc.
Void | VoidResult | This is returned when script code forwards the result of a host method that returns no value.
Host Object | Native .NET type | This includes all .NET types not mentioned above, including value types (enums, structs, etc.), and instances of all other classes. Script code can only create these objects by invoking a host method or constructor. They are returned to the host in their native .NET form.
Script Object | ScriptObject | This includes all native script objects that have no .NET representation. C#'s dynamic keyword provides a convenient way to access them.
Other | Unspecified | This includes host types and other ClearScript-specific objects intended for script code use only. It may also include language-specific values that the ClearScript library does not support.

See Also

#### Reference

ScriptEngine Class
Evaluate Overload
Microsoft.ClearScript Namespace

Copyright © Microsoft Corporation. All rights reserved.

Send comments on this topic to Microsoft