__Bingo!
I think that this TDL tag may be very useful to other developers too, as it opens up the possibility of writing custom template code based on the presence of various standard fields (such as "Deleted").
Here are the ammends to the TDL related code - and yes, it is all copied and borrowed from what is already there
Otis - if you would like me to email you the files with these changes, let me know.
Thanks for your help.
Interpreter.cs:
Line 200:
case NonTerminalType.IfHasEntityFieldStart:
Line 369:
case NonTerminalType.IfHasEntityFieldStart:
HandleIfHasEntityFieldStart();
break;
_ Line 3117:_
/// <summary>
/// Handles an if start of type 'HandleIfHasEntityField'. Will walk the statements between the start and IfEnd statement, if
/// the expression resolves to true, otherwise all statements are skipped. Will keep track of nested ifs when skipping the
/// inner if body.
/// </summary>
private void HandleIfHasEntityFieldStart()
{
// if there is no current entity, this if statement is not executed.
if(_currentEntity==null)
{
return;
}
NonTerminal current = (NonTerminal)_parseTree[_nonTerminalIndex];
// negate the expression if a NOT is present.
bool negate = (((Token)((IToken)current.Tokens[2]).TokenID)==Token.Not);
//get field name to search for
int index=3;
if(negate)
{
// not present, relationtype token is at index 4:
// 0 1 2 3 4
// <[ If Not HasEntityField FieldName ]>
index=4;
}
IToken fieldToken = (IToken)current.Tokens[index];
string fieldName = fieldToken.LiteralMatchedTokenText;
bool executeIfBody = ((_currentEntity.Fields[fieldName] != null)^negate);
if(executeIfBody)
{
// execute if statement
_nonTerminalIndex++;
InnerIfHandler();
}
else
{
// move current index to corresponding EndIf statement.
_nonTerminalIndex = current.CorrespondingEndNTIndex;
}
}
EnumConstants.cs
Line 90:
HasEntityField,
_ Line 245:_
IfHasEntityFieldStart,
** Parser.cs**
_ Line 940L_
case Token.HasEntityField:
tokensInStatement.Add(_tokenStream.Dequeue());
toReturn = new NonTerminal(NonTerminalType.IfHasEntityFieldStart);
break;
_ Line 1096:_
// HasRelationStart and RelationTypeStart have an argument: relation type
if(toReturn.Type==NonTerminalType.IfHasEntityFieldStart)
{
// peek for token.
currentToken = (IToken)_tokenStream.Peek();
if(((Token)currentToken.LiteralMatchedTokenText.Length > 0))
{
// valid argument. Pop it.
tokensInStatement.Add(_tokenStream.Dequeue());
StripWhiteSpace();
}
}
_ Line 1840:_
// 'HasEntityField'
_tokenDefinitions.Add(new TDLTokenDefinition((int)Token.HasEntityField, @"HasEntityField", RegexOptions.Compiled | RegexOptions.IgnoreCase));