GeneralFormatCollection Class
Represents a typed collection of general formats.
Inheritance Hierarchy
SystemObject
  Aspose.Words.FieldsGeneralFormatCollection

Namespace: Aspose.Words.Fields
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.11
Syntax
public class GeneralFormatCollection : IEnumerable<GeneralFormat>, 
	IEnumerable

The GeneralFormatCollection type exposes the following members.

Properties
  NameDescription
Public propertyCode exampleCount
Gets the total number of the items in the collection.
Public propertyCode exampleItem
Gets a general format at the specified index.
Methods
  NameDescription
Public methodCode exampleAdd
Adds a general format to the collection.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodCode exampleGetEnumerator
Returns an enumerator object.
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodCode exampleRemove
Removes all occurrences of the specified general format from the collection.
Public methodCode exampleRemoveAt
Removes a general format occurrence at the specified index.
Public methodToString (Inherited from Object.)
Examples
Shows how to format fields
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Use a document builder to insert field with no format
Field field = builder.InsertField("= 2 + 3");

// We can format our field here instead of in the field code
FieldFormat format = field.Format;
format.NumericFormat = "$###.00";
field.Update();

// Apply a date/time format
field = builder.InsertField("DATE");
format = field.Format;
format.DateTimeFormat = "dddd, MMMM dd, yyyy";
field.Update();

// Apply 2 general formats at the same time
field = builder.InsertField("= 25 + 33");
format = field.Format;
format.GeneralFormats.Add(GeneralFormat.LowercaseRoman);
format.GeneralFormats.Add(GeneralFormat.Upper);
field.Update();

int index = 0;
using (IEnumerator<GeneralFormat> generalFormatEnumerator = format.GeneralFormats.GetEnumerator())
{
    while (generalFormatEnumerator.MoveNext())
    {
        Console.WriteLine($"General format index {index++}: {generalFormatEnumerator.Current}");
    }
}

Assert.AreEqual("LVIII", field.Result);
Assert.AreEqual(2, format.GeneralFormats.Count);
Assert.AreEqual(GeneralFormat.LowercaseRoman, format.GeneralFormats[0]);

// Removing field formats
format.GeneralFormats.Remove(GeneralFormat.LowercaseRoman);
format.GeneralFormats.RemoveAt(0);
Assert.AreEqual(0, format.GeneralFormats.Count);
field.Update();

// Our field has no general formats left and is back to default form
Assert.AreEqual("58", field.Result);
See Also