本文整理匯總了C#中AstNode.GetChild方法的典型用法代碼示例。如果您正苦於以下問題:C# AstNode.GetChild方法的具體用法?C# AstNode.GetChild怎麽用?C# AstNode.GetChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類AstNode
的用法示例。
在下文中一共展示了AstNode.GetChild方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Evaluate
/// <summary>
/// Performs the specified action on an expression tree.
/// </summary>
/// <returns>The top node of the results.</returns>
/// <exception>ApplicationException</exception>
/// <param name="node">The top node of the tree.</param>
/// <param name="data">Data passed to the visitor (Typically not used).</param>
/// <param name="pv">Visitor object that can be used to descend the tree.</param>
/// <param name="stack">The stack to operate on.</param>
/// <exception cref="ApplicationException">If operator must have 3 arguments.</exception>
public virtual object Evaluate( AstNode node, object data, IAstNodeVisitor pv, Stack< double? > stack )
{
if ( node.NumChildren != 3 )
throw new ApplicationException( "If operator must have 3 arguments." );
AstNode condition = node.GetChild( 0 );
condition.Accept( pv, data );
CheckStack( stack );
double? condVal = stack.Pop();
if ( condVal.HasValue && ( condVal > 0.0 ) )
{
AstNode trueNode = node.GetChild( 1 );
trueNode.Accept( pv, data );
return data;
}
AstNode falseNode = node.GetChild( 2 );
falseNode.Accept( pv, data );
return data;
}