HostFunctionsnewObjT(Object) Method |
Creates a host object of the specified type. This version is invoked if the specified
type can be used as a type argument.
Namespace: Microsoft.ClearScriptAssembly: ClearScript.Core (in ClearScript.Core.dll) Version: 7.4.5
Syntax public T newObj<T>(
params Object[] args
)
Public Function newObj(Of T) (
ParamArray args As Object()
) As T
public:
generic<typename T>
T newObj(
... array<Object^>^ args
)
member newObj :
args : Object[] -> 'T
Parameters
- args Object
- Optional constructor arguments.
Type Parameters
- T
- The type of object to create.
Return Value
TA new host object of the specified type.
Remarks
This function is provided for script languages that do not support external
instantiation. It is overloaded with newObj(Object, Object) and
selected at runtime if T can be used as a type argument.
For information about the mapping between host members and script-callable properties
and methods, see
AddHostObject.
Example
The following code imports the
Random class, creates an
instance using the
Random(Int32)
constructor, and calls the
NextDouble method.
It assumes that an instance of
ExtendedHostFunctions is exposed under
the name "host"
(see
AddHostObject).
var RandomT = host.type("System.Random");
var random = host.newObj(RandomT, 100);
var value = random.NextDouble();
See Also