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: 19.11
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 fieldIf = (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"
fieldIf.LeftExpression = "0";
fieldIf.ComparisonOperator = "=";
fieldIf.RightExpression = "1";
fieldIf.TrueText = "True";
fieldIf.FalseText = "False";

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

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

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

doc.UpdateFields();
doc.Save(ArtifactsDir + "Field.If.docx");
See Also