AFAnnotations Class
- Last UpdatedNov 18, 2025
- 7 minute read
- PI System
- AF SDK 2024 R2
- Developer

Inheritance Hierarchy
OSIsoft.AF.DataAFAnnotations
Namespace: OSIsoft.AF.Data
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
public sealed class AFAnnotations : IList<AFAnnotation>, ICollection<AFAnnotation>, IEnumerable<AFAnnotation>, IEnumerable, IList, ICollection
Public NotInheritable Class AFAnnotations Implements IList(Of AFAnnotation), ICollection(Of AFAnnotation), IEnumerable(Of AFAnnotation), IEnumerable, IList, ICollection Dim instance As AFAnnotations
public ref class AFAnnotations sealed : IList<AFAnnotation^>, ICollection<AFAnnotation^>, IEnumerable<AFAnnotation^>, IEnumerable, IList, ICollection
[<SealedAttribute>] type AFAnnotations = class interface IList<AFAnnotation> interface ICollection<AFAnnotation> interface IEnumerable<AFAnnotation> interface IEnumerable interface IList interface ICollection end
The AFAnnotations type exposes the following members.
Constructors
| Name | Description | |
|---|---|---|
| AFAnnotations | Initializes a new instance of the AFAnnotations class |
Properties
| Name | Description | |
|---|---|---|
| Count |
Gets the number of items actually contained in the collection.
| |
| Item |
Gets or sets the item at the specified index.
|
Methods
| Name | Description | |
|---|---|---|
| Add |
Create a new AFAnnotation object and adds it to the list.
| |
| Clear |
Removes all items from the collection.
| |
| Contains |
The Contains method determines if an AFAnnotation exists in the list.
| |
| CopyTo |
Copies the entire collection to a compatible one-dimensional Array,
starting at the specified index of the target array.
| |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
| GetEnumerator |
Returns an enumerator that iterates through the collection.
| |
| GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| IndexOf |
Searches for the specified object and returns the zero-based index of the first
occurrence within the entire collection.
| |
| Insert |
Inserts an item into the collection at the specified index.
| |
| Remove |
Removes the first occurrence of a specific object from the collection.
| |
| RemoveAt |
Removes the item at the specified index of the collection.
| |
| ToString | Returns a string that represents the current object. (Inherited from Object.) |
Extension Methods
| Name | Description | |
|---|---|---|
| ChunkedByAFAnnotation |
This extension method breaks up search results into chunks to make it easier to
page through and process IEnumerableT collections in chunks.
(Defined by AFSDKExtension.) |
Remarks
A list of structured AFAnnotation objects associated with an historical data event. This list can be returned from the AFValue.GetAnnotation method. Because it is a list, there can be more than one structured AFAnnotation per AFValue. This collection of annotations is only used with structured historical data events. Annotations associated with asset data such as AFEventFrame or AFElement are returned as a simple list of AFAnnotation objects and do not use this class.
| This list only supports PIPoint annotations. |
| This method, property, or class is not available in the legacy .NET 3.5 version of the SDK. |
Examples
// This example demonstrates how to create an attribute for an // element and retrieve and set annotations on values. // Get the Database PISystems myPISystems = new PISystems(); PISystem myPISystem = myPISystems.DefaultPISystem; AFDatabase myDB = myPISystem.Databases.DefaultDatabase; // Create an Element AFElement myElement = myDB.Elements.Add("MyElement"); // Create an Attribute AFAttribute myAttribute = myElement.Attributes.Add("MyAttribute"); myAttribute.DefaultUOM = myPISystem.UOMDatabase.UOMs["kelvin"]; myAttribute.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(myPISystem); myAttribute.ConfigString = @"\\%Server%\sinusoid;ReadOnly=False"; // Create New Simple Annotation AFValue myValue1 = new AFValue(155.432, AFTime.Now); myValue1.SetAnnotation("New Event with Simple Annotation"); myAttribute.Data.UpdateValue(myValue1, AFUpdateOption.InsertNoCompression); // Update an Existing Annotation myValue1.SetAnnotation(100); myAttribute.Data.UpdateValue(myValue1, AFUpdateOption.Replace); // Create an AFFile to be used as an Annotation value string path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "TestFile.txt"); using (System.IO.File.Create(path)) { } AFFile myFile = new AFFile(); myFile.Upload(path); // Create New Structured Annotation AFAnnotations myAnnotations = new AFAnnotations(); AFValue myValue2 = new AFValue(255.543); AFAnnotation myAnnotation = myAnnotations.Add("Annotation#1", 400.456); myAnnotation.Description = "1st Annotation is a Double."; myAnnotation = myAnnotations.Add("Annotation#2", "My Annotation Value"); myAnnotation.Description = "2nd Annotation is a String."; myAnnotation = myAnnotations.Add("Annotation#3", myFile); myAnnotation.Description = "3rd Annotation is an AFFile."; myValue2.SetAnnotation(myAnnotations); myAttribute.Data.UpdateValue(myValue2, AFUpdateOption.InsertNoCompression); // Read Annotations object theAnnotation = myValue1.GetAnnotation(); DisplayAnnotation(myValue1, theAnnotation); theAnnotation = myValue2.GetAnnotation(); DisplayAnnotation(myValue2, theAnnotation); AFValue myValue = myAttribute.GetValue(); theAnnotation = myValue.GetAnnotation(); DisplayAnnotation(myValue, theAnnotation);
' This example demonstrates how to create an attribute for an ' element and retrieve and set annotations on values. ' Get the Database Dim myPISystems As New PISystems Dim myPISystem As PISystem = myPISystems.DefaultPISystem Dim myDB As AFDatabase = myPISystem.Databases.DefaultDatabase ' Create An Element Dim myElement As AFElement = myDB.Elements.Add("MyElement") ' Create an Attribute Dim myAttribute As AFAttribute = myElement.Attributes.Add("MyAttribute") myAttribute.DefaultUOM = myPISystem.UOMDatabase.UOMs("Kelvin") myAttribute.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(myPISystem) myAttribute.ConfigString = "\\%Server%\sinusoid;ReadOnly=False" ' Create New Simple Annotation Dim myValue1 As AFValue = New AFValue(155.432, AFTime.Now) myValue1.SetAnnotation("New Event with Simple Annotation") myAttribute.Data.UpdateValue(myValue1, AFUpdateOption.InsertNoCompression) ' Update an Existing Annotation myValue1.SetAnnotation(100) myAttribute.Data.UpdateValue(myValue1, AFUpdateOption.Replace) ' Create an AFFile to be used as an Annotation value Dim path As String = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "TestFile.txt") Dim fs As FileStream = System.IO.File.Create(path) fs.Close() Dim myFile As AFFile = New AFFile myFile.Upload(path) ' Create New Structured Annotation Dim myAnnotations As AFAnnotations = New AFAnnotations Dim myValue2 As AFValue = New AFValue(255.543) Dim myAnnotation As AFAnnotation = myAnnotations.Add("Annotation#1", 400.456) myAnnotation.Description = "1st Annotation is a Double." myAnnotation = myAnnotations.Add("Annotation#2", "My Annotation Value") myAnnotation.Description = "2nd Annotation is a String." myAnnotation = myAnnotations.Add("Annotation#3", myFile) myAnnotation.Description = "3rd Annotation is an AFFile." myValue2.SetAnnotation(myAnnotations) myAttribute.Data.UpdateValue(myValue2, AFUpdateOption.InsertNoCompression) ' Read Annotations Dim theAnnotation As Object = myValue1.GetAnnotation DisplayAnnotation(myValue1, theAnnotation) theAnnotation = myValue2.GetAnnotation DisplayAnnotation(myValue2, theAnnotation) Dim myValue As AFValue = myAttribute.GetValue theAnnotation = myValue.GetAnnotation DisplayAnnotation(myValue, theAnnotation)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
/// <summary> /// Display information about the annotated value. /// </summary> /// <param name="theValue"> /// The AFValue associated with the specified annotation value. /// </param> /// <param name="theAnnotation"> /// The annotation value associated with the specified AFValue. /// </param> static private void DisplayAnnotation(AFValue theValue, object theAnnotation) { AFAnnotations theAnnotations = theAnnotation as AFAnnotations; if (theAnnotations == null) { Console.WriteLine("Simple Annotation for Value '{0}' = '{1}'", theValue, theAnnotation); } else { Console.WriteLine("Structured Annotation for Value '{0}':", theValue); foreach (AFAnnotation item in theAnnotations) { Console.WriteLine(" Value = '{0}', Description = '{1}', Creator = '{2}'", item.Value, item.Description, item.Creator); } } }
''' <summary> ''' Display information about the annotated value. ''' </summary> ''' <param name="theValue"> ''' The AFValue associated with the specified annotation value. ''' </param> ''' <param name="theAnnotation"> ''' The annotation value associated with the specified AFValue. ''' </param> Private Shared Sub DisplayAnnotation(ByVal theValue As AFValue, ByVal theAnnotation As Object) Dim theAnnotations As AFAnnotations = TryCast(theAnnotation, AFAnnotations) If (theAnnotations Is Nothing) Then Console.WriteLine("Simple Annotation for Value '{0}' = '{1}'", theValue, theAnnotation) Else Console.WriteLine("Structured Annotation for Value '{0}':", theValue) For Each item As AFAnnotation In theAnnotations Console.WriteLine(" Value = '{0}', Description = '{1}', Creator = '{2}'", item.Value, item.Description, item.Creator) Next End If End Sub
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.