I saw a recent post on Scott’s Blog about what’s valid inside an expression shape.
It gave a helpful list of expressions that are not allowed inside the Expression Shape. I was surprised by one of the items in the list, the “if”. I had been using “if” inside an Expression Shape in the Beta.I wondered if this was no longer possible in the RTM release. So, I set up a simple sample project to test this out.
First off, you might ask: “Why would you not use the Decision Shape?”
Well, I used “if” inside the Expression Shape for a few reasons:
1. To make the visual size of the Orchestration smaller
2. To do quick Boolean checks like if a file exists
3. It was easier to drop in a quick line of “if” code rather then mess with the huge Decision Shape. Ok, this point could be debatable…
I have put together a sample testing the use of“if” inside an Expression Shape and a sample showing how “if” can not be used inside a Message Assignment Shape.
DOWNLOAD: Get the sample here!
Set up is easy, just unzip the SampleIFStatements folder and put it on your C: drive. Then, build and deploy the ExpressionIF project. I use early binding so the send and receive ports will be created for you. Then, try to build the MessageAssignmentIF project. Note the difference how the two Orchestrations use “if”. This project should not build and should say illegal use of “if”.
To run the sample, drop the start messages named Start_False.xml and Start_True.xml into c:\ SampleIFStatements\In. You will get your results in the Out directory. The Results node will be changed based on the Boolean value. If all else fails, read the ReadMe.txt file.
Key Take Home Points:
– “if” is allowed inside the Expressions Shape
– “if” is not allowed inside the Message Assignment Shape
Take Away: It is possible to use “if” outside of the Decision Shape inside an Expression Shape. But, it should be used cautiously since it could confuse developers who are looking for the Decision Shape.