FieldIfComparisonResult
Contents
[
Hide
]FieldIfComparisonResult enumeration
Specifies the result of the IF field condition evaluation.
public enum FieldIfComparisonResult
Values
Name | Value | Description |
---|---|---|
Error | 0 | There is an error in the condition. |
True | 1 | The condition is true . |
False | 2 | 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: ");
FieldIf field = (FieldIf)builder.InsertField(FieldType.FieldIf, true);
field.LeftExpression = "0";
field.ComparisonOperator = "=";
field.RightExpression = "1";
// The IF field will display a string from either its "TrueText" property,
// or its "FalseText" property, depending on the truth of the statement that we have constructed.
field.TrueText = "True";
field.FalseText = "False";
field.Update();
// In this case, "0 = 1" is incorrect, so the displayed result will be "False".
Assert.AreEqual(" IF 0 = 1 True False", field.GetFieldCode());
Assert.AreEqual(FieldIfComparisonResult.False, field.EvaluateCondition());
Assert.AreEqual("False", field.Result);
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";
field.Update();
// This time the statement is correct, so the displayed result will be "True".
Assert.AreEqual(" IF 5 = \"2 + 3\" True False", field.GetFieldCode());
Assert.AreEqual(FieldIfComparisonResult.True, field.EvaluateCondition());
Assert.AreEqual("True", field.Result);
doc.UpdateFields();
doc.Save(ArtifactsDir + "Field.IF.docx");
See Also
- namespace Aspose.Words.Fields
- assembly Aspose.Words