John,
Just some comments on the layout below:

 I needed to do a similar thing.  My solution was to create two new custom
functions, regex::replace and file::get-file.

 They are very simple and have no error checking :-)

<target name="initregex">
<script language="C#" prefix="regex">
<code><![CDATA[
[Function("replace")]
public static string RegexReplace(string
pSource, string pSearch, string pReplace) {
System.Text.RegularExpressions.Regex
re = new System.Text.RegularExpressions.Regex(pSearch,
System.Text.RegularExpressions.RegexOptions.Singleline);
return re.Replace(pSource,
pReplace);
}
]]></code>
</script>

<script language="C#" prefix="file">
<code><![CDATA[
[Function("get-file")]
public static string GetFile( string
pFileName ) {
string s = "";
using (System.IO.StreamReader sr =
new System.IO.StreamReader(pFileName)) {
s = sr.ReadToEnd();
}
return s;
}

]]></code>
</script>




1) you don't need a script block for each function. You can put multiple function definitions in a single block - oh I see - you're using 2 blocks to have 2 different prefixes.
2) By putting the script block/blocks at the top level it/they will always be called - it you won't need to explicitly call the initregex target.
3) as a general rule - for built in functions we try and ensure that they are side-effect free and use custom tasks where somthing on the system (eg a file ) needs to be changed. Of course you are free to disregard this guideline in your own buildscripts where you just want to get things working.


Ian



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Nant-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to