Click or drag to resize

FieldIfComparisonResult Enumeration

Specifies the result of the IF field condition evaluation.

Namespace:  Aspose.Words.Fields
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0

Syntax

public enum FieldIfComparisonResult

Members

  Member nameValueDescription
Error0 There is an error in the condition.
True1 The condition is true.
False2 The condition is false.

Examples

Shows how to insert an if field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write("Statement 1: ");

// Use document builder to insert an if field
FieldIf field = (FieldIf)builder.InsertField(FieldType.FieldIf, true);

// The if field will output either the TrueText or FalseText string into the document, depending on the truth of the statement
// In this case, "0 = 1" is incorrect, so the output will be "False"
field.LeftExpression = "0";
field.ComparisonOperator = "=";
field.RightExpression = "1";
field.TrueText = "True";
field.FalseText = "False";

Assert.AreEqual(" IF  0 = 1 True False", field.GetFieldCode());
Assert.AreEqual(FieldIfComparisonResult.False, field.EvaluateCondition());

// This time, the statement is correct, so the output will be "True"
builder.Write("\nStatement 2: ");
field = (FieldIf)builder.InsertField(FieldType.FieldIf, true);
field.LeftExpression = "5";
field.ComparisonOperator = "=";
field.RightExpression = "2 + 3";
field.TrueText = "True";
field.FalseText = "False";

Assert.AreEqual(" IF  5 = \"2 + 3\" True False", field.GetFieldCode());
Assert.AreEqual(FieldIfComparisonResult.True, field.EvaluateCondition());

doc.UpdateFields();
doc.Save(ArtifactsDir + "Field.IF.docx");

See Also