Thatcher,

That depends on the multiplicity of the nested build element.

A) 0...1

To expose a nested build element, the type of the property that backs the 
nested element must derive from NAnt.Core.Element, and a 
BuildElementAttribute must have been applied to it.

* Example:

=====

using NAnt.Core;
using NAnt.Core.Attributes;

public class ClassElement : Element {
    private string _className;

    [TaskAttribute("name")]
    public string ClassName {
        get { return _className; }
        set { _className = value; }
    }
}

=====

using NAnt.Core;
using NAnt.Core.Attributes;

[TaskName("mcc")]
public class MccTask : Task {
    private ClassElement _class;

    [BuildElement("class")]
    public ClassElement Class {
        get { return _class; }
        set { _class = value: }
    }

    protected override void ExecuteTask() {
        // perform necessary actions here
    }
}

====

<mcc>
    <class name="..." />
</mcc>

B) 0...n

If you want to support a collection of nested elements, then the type of the 
property that backs the nested elements must be either:

    1) an array (of a type deriving from NAnt.Core.Element)
    2) a type implementing ICollection
    3) a strongly typed collection (for a type deriving from 
NAnt.Core.Element).

A collection of nested elements can be exposed as:

    * a flat array

        This is done by applying a BuildElementArrayAttribute to the 
property.

    * an array wrapped in another element

        This is done by applying a BuildElementCollectionAttribute to the 
property.

        => Only supported for arrays (1) and strongly typed collections (2).

* Example using BuildElementArray:

private ClassElement[] _classes;

[BuildElementArray ("class")]
public ClassElement[] Classes {
  get { return _classes; }
  set { _classes = value; }
}

Build fragment:

<mcc ...>
    <class ... />
    <class ... />
    <class ... />
</mcc>

* Example using BuildElementCollection

private ClassElementCollection_classes;

[BuildElementCollection ("classes", "class")]
public ClassElementCollection Classes {
  get { return _classes; }
}

Build fragment:

<mcc ...>
    <classes>
        <class .... />
    <classes>
</mcc>

Hope this helps,

Gert
----- Original Message ----- 
From: "Thatcher Clay" <[EMAIL PROTECTED]>
To: <nant-users@lists.sourceforge.net>
Sent: Monday, June 18, 2007 10:50 PM
Subject: [NAnt-users] Creating custom Nant Tasks


Hello,



Is there anyone who has had experience creating custom Nant tasks?  I am
trying to hook in mcc, a matlab compiler, into Nant, but I am running
into issues when I try to parse nested elements.  What I want to be able
to parse looks something like this:



<mcc attributes....>

            <class name="foo">

            <mfile name="bar.m" />

</class>

</mcc>



I can make it work just using the attributes on the top level, but when
I try to add a nested element to the task I get an error message saying
that "mcc does not support the nested build element class.  Does anyone
know how to create a custom task that accepts nested elements?



Thanks,

Thatcher



----------------------------------------

This message is intended exclusively for the individual(s) or entity to 
which it is addressed. It may contain information that is proprietary, 
privileged or confidential or otherwise legally exempt from disclosure. If 
you are not the named addressee, you are not authorized to read, print, 
retain, copy or disseminate this message or any part of it. If you have 
received this message in error, please notify the sender immediately by 
e-mail and delete all copies of the message.




--------------------------------------------------------------------------------


> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/


--------------------------------------------------------------------------------


> _______________________________________________
> NAnt-users mailing list
> NAnt-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nant-users
> 



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to