NAntScript
Help
Task Reference
<funcdef> |
v1.2.0 |
Creates a custom function containing NAnt tasks.
Define a function by specifying a name, a namespace and a list of function parameters. A custom function is created that runs each of the tasks in the <do/> parameter replacing function parameters before execution.
A special parameter __$return__ must be set during the <do/> block that is the return value of the function. Default type of this is 'string', but 'int' and 'bool' functions can also be written by setting a attribute returnType on the funcdef.
Function parameters are referenced in the <do/> section using the syntax __parameter name__. They are all required, and are given to the function in the same order as they are in the funcparams list. The type of a parameter defaults to 'string', but 'int' and 'bool' parameters can also be done by setting the 'type' attribute on the funcparam.
| Attribute | Type | Description | Required |
|---|---|---|---|
| name | string | The name for the custom function | True |
| namespace | string | The namespace for the custom function | True |
| returnType | string | The return type for the function (defaults to string) | False |
| failonerror | bool | False | |
| if | bool | False | |
| unless | bool | False | |
| verbose | bool | False |
Describes a func parameter to a custom scripted function
| Attribute | Type | Description | Required |
|---|---|---|---|
| name | string | The parameter name. | True |
| type | string | The parameter type (defaults to string) | False |
Create a custom function that takes one parameter, and which returns that value.
<funcdef name="testFunc" namespace="tests">
<funcparams>
<funcparam name="test" type="string" />
</funcparams>
<do>
<property name="__$return__" value="__test__" />
</do>
</funcdef>
<fail unless="${tests::testFunc('foo') == 'foo'}" />