ClearScript Library
ClearScript Library
ClearScript Library Reference
Microsoft.ClearScript
ScriptEngine Class
ScriptEngine Methods
AddHostObject Method
AddHostObject(String, Object) Method
AddHostObject(String, HostItemFlags, Object) Method

# ScriptEngineAddHostObject(String, HostItemFlags, Object) Method

Exposes a host object to script code with the specified options.
Namespace: Microsoft.ClearScript
Assembly: ClearScript.Core (in ClearScript.Core.dll) Version: 7.5.0
Syntax
C#
VB
C++
F#
Copy

    public void AddHostObject(
    	string itemName,
    	HostItemFlags flags,
    	Object target
    )

    Public Sub AddHostObject (
    	itemName As String,
    	flags As HostItemFlags,
    	target As Object
    )

    public:
    virtual void AddHostObject(
    	String^ itemName,
    	HostItemFlags flags,
    	Object^ target
    ) sealed

    abstract AddHostObject :
            itemName : string *
            flags : HostItemFlags *
            target : Object -> unit
    override AddHostObject :
            itemName : string *
            flags : HostItemFlags *
            target : Object -> unit

#### Parameters

itemName String
  A name for the new global script item that will represent the object.
flags HostItemFlags
  A value that selects options for the operation.
target Object
  The object to expose.

#### Implements

IScriptEngineAddHostObject(String, HostItemFlags, Object)
Remarks

Once a host object is exposed to script code, its members are accessible via the script language's native syntax for member access. The following table provides details about the mapping between host members and script-accessible properties and methods.

Member Type | Exposed As | Remarks
--- | --- | ---
Constructor | N/A | To invoke a constructor from script code, call HostFunctions.newObj(T).
Property/Field | Property | N/A
Method | Method | Overloaded host methods are merged into a single script-callable method. At runtime the correct host method is selected based on the argument types.
Generic Method | Method | The ClearScript library supports dynamic C#-like type inference when invoking generic methods. However, some methods require explicit type arguments. To call such a method from script code, you must place the required number of host type objects at the beginning of the argument list. Doing so for methods that do not require explicit type arguments is optional.
Extension Method | Method | Extension methods are available if the type that implements them has been exposed in the current script engine.
Indexer | Property | Indexers appear as properties named "Item" that accept one or more index values as arguments. In addition, objects that implement IList expose properties with numeric names that match their valid indices. This includes one-dimensional host arrays and other collections. Multidimensional host arrays do not expose functional indexers; you must use Array.GetValue and Array.SetValue instead.
Event | Property | Events are exposed as read-only properties of type EventSourceT.

See Also

#### Reference

ScriptEngine Class
AddHostObject Overload
Microsoft.ClearScript Namespace

Copyright © Microsoft Corporation. All rights reserved.

Send comments on this topic to Microsoft