From: <ia...@us...> - 2005-10-19 07:01:05
|
Update of /cvsroot/nantcontrib/NAntContrib/src/Functions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20516/src/Functions Modified Files: FileSetFunctions.cs Log Message: Update from Bill Martin to convert a fileset to a delimeted string Index: FileSetFunctions.cs =================================================================== RCS file: /cvsroot/nantcontrib/NAntContrib/src/Functions/FileSetFunctions.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FileSetFunctions.cs 4 Oct 2005 02:36:42 -0000 1.2 --- FileSetFunctions.cs 19 Oct 2005 07:00:56 -0000 1.3 *************** *** 19,22 **** --- 19,23 ---- using System; + using System.Text; using NAnt.Core; using NAnt.Core.Types; *************** *** 102,106 **** return (fs.FileNames.Count > 0); } ! #endregion Public Instance Methods } --- 103,153 ---- return (fs.FileNames.Count > 0); } ! /// <summary> ! /// Returns a delimited string of all the filenames within a <see cref="FileSet"/> with each filename ! /// separated by the specified delimiter string. ! /// </summary> ! /// <param name="fileset">The id of the fileset to check.</param> ! /// <param name="delimiter">String to separate filenames with.</param> ! /// <returns>A delimited string of the filenames within the specified FileSet.</returns> ! /// <exception cref="ArgumentException"><paramref name="fileset" /> is not a valid refid to a defined fileset.</exception> ! /// <example> ! /// <para> ! /// Displays a space-pipe-space separated string fo the files within a defined FileSet. ! /// </para> ! /// <code> ! /// <![CDATA[ ! /// <fileset id="test.fileset"> ! /// <include name="**/*.cs"> ! /// </fileset> ! /// <echo message="${fileset::to-string('test.fileset', ' | ')}"> ! /// ]]> ! /// </code> ! /// </example> ! [Function("to-string")] ! public string ToString(string fileset, string delimiter){ ! //Try to retrieve the specified fileset from the Data References on the project ! FileSet fs = base.Project.DataTypeReferences[fileset] as FileSet; ! ! //If the value was missing or the referenced type was not a fileset, then throw an exception ! if (fs == null){ ! throw new ArgumentException(string.Format("'{0}' is not a valid fileset reference", fileset)); ! } ! ! //We've got a valid fileset. Use a stringbuilder to build the delimiter separated list. ! StringBuilder sb = new StringBuilder(); ! ! //This is a loop as we need to omit the delimiter on the last element, and it's easier ! //to check the last element with a for loop than in a foreach loop. ! for (int i = 0; i < fs.FileNames.Count; i++){ ! string file = fs.FileNames[i]; ! sb.Append(file); ! //if this is not the last element, then append the delimiter ! if (i < fs.FileNames.Count - 1){ ! sb.Append(delimiter); ! } ! } ! //Now return the string representation of the FileSet. ! return sb.ToString(); ! } #endregion Public Instance Methods } |