Title: Testing if a value is an Int

You could use a custom function in VB (‘cause IsNumeric is more tricky in C#!).  Try something like:

 

    <script language="VB" prefix="numeric-tasks" >

        <code>

            <![CDATA[                

                [Function("is-integer")]

                Public Shared Function IsInteger(ByVal test As  Object)

               

                        Return (IsNumeric(test) AndAlso CInt(test) = Val(test))

 

                End Function

                ]]>

        </code>

    </script>

 

Which you can then call by using

 

            <task if=”${numeric-tasks::is-numeric(myproperty)}”>

            </task>

 

Where “myproperty” is the name of the property you wish to evaluate.

 

Note this is types freehand, so may have typos in it.

 

HTH,

 

Bill

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nau, Michael
Sent: 09 January 2006 18:43
To: nant-users@lists.sourceforge.net
Subject: [NAnt-users] Testing if a value is an Int

 

Is there a "clean" way to test if a property value is an integer? I've come up with a bit of a hack to accomplish this, but this raises an error in my build log (which shows up in my ccnet errors page…).

Here's my hack:

<property name="is.input.an.integer" value="${int::parse(input)}" failonerror="false"/>   
   
<if test="${property::exists('is.input.an.integer')}">
  <echo message="input is an integer"/> 
</if>

<ifnot test="${property::exists('is.input.an.integer')}">
  <echo message="input is not an integer"/> 
</ifnot>

Thanks,
-Mike

Reply via email to