How to iterate through recognized fields

Since IField object may contain items and children subobjects, it might look complicated to iterate over the fields.

Use the following code to display all fields inside IDocument:

 

 private void AppendToResult(IField field, StringBuilder result)
{
if (field.Value != null)
{
result.AppendFormat("{0} = {1}\n", field.FullName, field.Value.AsText.Text);
return;
}
if (field.Children != null)
{
foreach (IField childField in field.Children)
{
AppendToResult(childField, result);
}
}
if (field.Instances != null) {
foreach( IField instanceField in field.Instances)
{
AppendToResult(instanceField, result);
}
}
}

System.Text.StringBuilder result = new System.Text.StringBuilder();
FCEngine.IField documentAsField = (IField)document;
AppendToResult(documentAsField, result);

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Recently viewed