IScriptEngineAddHostObject(String, HostItemFlags, Object) Method |
Exposes a host object to script code with the specified options.
Namespace: Microsoft.ClearScriptAssembly: ClearScript.Core (in ClearScript.Core.dll) Version: 7.4.5
Syntax void AddHostObject(
string itemName,
HostItemFlags flags,
Object target
)
Sub AddHostObject (
itemName As String,
flags As HostItemFlags,
target As Object
)
void AddHostObject(
String^ itemName,
HostItemFlags flags,
Object^ target
)
abstract 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.
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