ClearScript Library
ClearScript Library
ClearScript Library Reference
Microsoft.ClearScript
HostFunctions Class
HostFunctions Methods
func Method
func(Int32, Object) Method
func<T>(Int32, Object) Method

# HostFunctionsfunc T(Int32, Object) Method

Creates a delegate that invokes a script function and returns a value of the specified type.
Namespace: Microsoft.ClearScript
Assembly: ClearScript.Core (in ClearScript.Core.dll) Version: 7.5.0
Syntax
C#
VB
C++
F#
Copy

    public Object func<T>(
    	int argCount,
    	Object scriptFunc
    )

    Public Function func(Of T) (
    	argCount As Integer,
    	scriptFunc As Object
    ) As Object

    public:
    generic<typename T>
    Object^ func(
    	int argCount,
    	Object^ scriptFunc
    )

    member func :
            argCount : int *
            scriptFunc : Object -> Object

#### Parameters

argCount Int32
  The number of arguments to pass to the script function.
scriptFunc Object
  The script function for which to create a delegate.

#### Type Parameters

T
  The return value type.

#### Return Value

Object
A new delegate that invokes the specified script function and returns a value of the specified type.
Remarks
This function creates a delegate that accepts argCount arguments and returns a value of the specified type. The type of all parameters is Object. Such a delegate is often useful in strongly typed contexts because of contravariance.
Example
The following code demonstrates delegating a callback to a script function. It assumes that an instance of ExtendedHostFunctions is exposed under the name "host" (see AddHostObject).
JavaScript
Copy

    // create and populate an array of strings
    var StringT = host.type("System.String");
    var array = host.newArr(StringT, 3);
    array.SetValue("first", 0);
    array.SetValue("second", 1);
    array.SetValue("third", 2);
    // import LINQ extensions
    var EnumerableT = host.type("System.Linq.Enumerable", "System.Core");
    // use LINQ to create an array of modified strings
    var selector = host.func(StringT, 1, function (value) { return value.toUpperCase(); });
    array = array.Select(selector).ToArray();

See Also

#### Reference

HostFunctions Class
func Overload
Microsoft.ClearScript Namespace
func(Int32, Object)
type(String, Object)
type(String, String, Object)

Copyright © Microsoft Corporation. All rights reserved.

Send comments on this topic to Microsoft