Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 713 posts 954 karma points
    Jun 17, 2011 @ 08:43
    Tom
    0

    Macro Parameters strongly typed?

    Hi guys I'm passing a number through as my macro parameter I was just wondering if this was strongly typed and how to check for it on the other end i.e. would it be something like @Parameter.numberOfItemsToDisplay != -1?

  • Eran Meir 401 posts 543 karma points
    Jun 17, 2011 @ 10:12
    Eran Meir
    1

    i think you need to cast it to an int varaible

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 20, 2011 @ 20:53
    Dan Diplo
    2

    All @Parameter values are passed as a string - you will need to cast them to their correct type. To avoid run-time errors it's probably best practice to do something like this:


    int noOfItems;
    if (!int.TryParse(Parameter.numberOfItemsToDisplay, out noOfItems))
    {
    noOfItems = 0;
    }

     That way if the parameter can't be cast (say it is missing or not a number) you get a default value of zero for it.

Please Sign in or register to post replies

Write your reply to:

Draft