#45 DoWhile task


Hi, I'm not really a coder, but I was able to hack something together and figured that others might find it useful, so I thought I'd post it here. If someone wants to add it to a dll or something to make it an official task item, that would be great. I don't currently have the skills to do so.

Here's the code:
<script language="C#">
public class DoWhileTask : TaskContainer
#region Private Instance Fields

private string _booleanproperty;

#endregion Private Instance Fields

#region Public Instance Properties

[TaskAttribute("booleanproperty", Required=true)]
public string BooleanProperty
get { return _booleanproperty; }
set { _booleanproperty = value; }

#endregion Public Instance Properties

#region Protected Instance Properties

protected virtual bool BooleanTrue
bool ret = true;

if (BooleanProperty != null)
ret = Project.ExpandProperties(Project.Properties[BooleanProperty], Location).ToUpper() == "TRUE";

return ret;

#endregion Protected Instance Properties

#region Override implementation of TaskContainer

protected override void ExecuteTask()
if (!Project.Properties.Contains(BooleanProperty))
Log(Level.Error, "Property '" + BooleanProperty + "' does not exist.");
throw new BuildException("Property '" + BooleanProperty + "' does not exist.");
while (BooleanTrue)

#endregion Override implementation of TaskContainer

Feel free to improve upon it or whatever - like I said I'm not a coder and don't really know what I'm doing, just hacked this together using source from the if and foreach tasks as a guide.

It's function is very simple. You give it the name of a property, and it will repeat the embedded tasks until that property evaluates to false. For example:
<property name="DoWhile" value="True" />
<dowhile booleanproperty="DoWhile">
[put some tasks here]
<property name="DoWhile" value="False" if="[processing tasks are complete]" />

Here's a working copy-and-paste example:
<property name="i" value="0" />
<property name="while" value="${5 >= int::parse(i)}" />
<dowhile booleanproperty="while" if="${while}" >
<property name="i" value="${int::parse(i) + 1}" />
<property name="while" value="${5 >= int::parse(i)}" />



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks