NAnt SDK Documentation - v0.92

TaskAttributeAttribute Class

Indicates that property should be treated as a XML attribute for the task.

For a list of all members of this type, see TaskAttributeAttribute Members.

System.Object
   System.Attribute
      NAnt.Core.Attributes.BuildAttributeAttribute
         NAnt.Core.Attributes.TaskAttributeAttribute

[Visual Basic]
<AttributeUsage(Inherited:=True, ValidOn:=AttributeTargets.Property, AllowMultiple:=False)>
NotInheritable Public Class TaskAttributeAttribute
    Inherits BuildAttributeAttribute
[C#]
[AttributeUsage(Inherited=True, ValidOn=AttributeTargets.Property, AllowMultiple=False)]
public sealed class TaskAttributeAttribute : BuildAttributeAttribute

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Example

Examples of how to specify task attributes

 // task XmlType default is string
 [TaskAttribute("out", Required=true)]
 string _out = null; // assign default value here

 [TaskAttribute("optimize")]
 [BooleanValidator()]
 // during ExecuteTask you can safely use Convert.ToBoolean(_optimize)
 string _optimize = Boolean.FalseString;

 [TaskAttribute("warnlevel")]
 [Int32Validator(0,4)] // limit values to 0-4
 // during ExecuteTask you can safely use Convert.ToInt32(_optimize)
 string _warnlevel = "0";

 [BuildElement("sources")]
 FileSet _sources = new FileSet();
 
NOTE: Attribute values must be of type of string if you want to be able to have macros. The field stores the exact value during Initialize. Just before ExecuteTask is called NAnt will expand all the macros with the current values.

Requirements

Namespace: NAnt.Core.Attributes

Assembly: NAnt.Core (in NAnt.Core.dll)

See Also

TaskAttributeAttribute Members | NAnt.Core.Attributes Namespace