Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

AFElement.ConvertTo Method

  • Last UpdatedNov 18, 2025
  • 3 minute read
AFElement.ConvertTo Method
Converts the current object to the specified type of an AFElement.

Namespace:  OSIsoft.AF.Asset
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182

Syntax

public AFElement ConvertTo(
	Type destinationType
)
Public Function ConvertTo ( 
	destinationType As Type
) As AFElement

Dim instance As AFElement
Dim destinationType As Type
Dim returnValue As AFElement

returnValue = instance.ConvertTo(destinationType)
public:
AFElement^ ConvertTo(
	Type^ destinationType
)
member ConvertTo : 
        destinationType : Type -> AFElement 

Parameters

destinationType
Type: SystemType
The Type to convert the current object to. The destination type must be AFElement or inherit from AFElement.

Return Value

Type: AFElement
An AFElement that represents the converted type. See CreateInstance(Type, BindingFlags, Binder, Object, CultureInfo) for a list of additional exceptions that might be thrown by this method.

Exceptions

ExceptionCondition
ArgumentNullException The destinationType is .
ArgumentException The destinationType is not a RuntimeType.
NotSupportedException The conversion could not be performed.

Remarks

The most common type of conversion is to convert from an element to a more specific type of element like AFModel. When converting from a more specific type of an element to an AFElement, information that is specific to that type will be lost. For example, converting an AFModel to back to an AFElement will lose any AFConnections and AFLayers that it has defined.

Before returning, the CheckIn method will automatically be called to save the new type of the object to the server. Therefore, this operation cannot be undone by calling UndoCheckOut(Boolean).

Important note Important
The element must be saved to the server before converting. Also, the element being converted cannot have multiple versions.

Examples

// This example demonstrates how to convert an element to a model.

// Get the Database
PISystems myPISystems = new PISystems();
AFDatabase myDB = myPISystems.DefaultPISystem.Databases.DefaultDatabase;

// Create an Element
AFElement myElement = myDB.Elements.Add("MyElement");
myElement.ApplyChanges();

// Convert the Element to a Model
AFModel myModel = (AFModel)myElement.ConvertTo(typeof(AFModel));

// Once an element has been converted, it will always be a model.  Output will be "AFModel"
myElement = myDB.Elements["MyElement"];
Console.WriteLine("MyElement is of type: {0}", myElement.GetType());
' This example demonstrates how to convert an element to a model.

' Get the Database
Dim myPISystems As New PISystems()
Dim myDB As AFDatabase = myPISystems.DefaultPISystem.Databases.DefaultDatabase

' Create an Element
Dim myElement As AFElement = myDB.Elements.Add("MyElement")
myElement.ApplyChanges()
myDB.CheckIn()

' Convert the Element to a Model
Dim myModel As AFModel = CType(myElement.ConvertTo(GetType(AFModel)), AFModel)

' Once an element has been converted, it will always be a model.  Output will be "AFModel"
myElement = myDB.Elements("MyElement")
Console.WriteLine("MyElement is of type: {0}", myElement.GetType())

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.

Version Information

AFSDK


See Also

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in