C# Wrapper Classes

In addition to the direct bindings to HOOPS Exchange binaries, the C# API provides high-level classes called wrappers.

Wrapper classes encapsulate both the entity handle and a local copy of its data structure, providing a C#-idiomatic interface to HOOPS Exchange. For example, a model file entity managed by an A3DAsmModelFile/A3DAsmModelFileData set has a wrapper class called A3DAsmModelFileWrapper.

These classes offer features such as constructors, resource management, inheritance, and properties. However, the current version of the C# API limits wrappers to short-lived, read-only entities. For other functionalities, you can still fallback to call bindings.

Comparison with Struct Bindings

Wrapper classes enhance the struct bindings by providing:

Struct Initialization

Wrapper classes provide default constructors that initialize internal data structures using API.Initialize().

var export_params = new A3DRWParamsExportXMLDataWrapper();

Data Load

When instantiated with an entity handle, wrapper classes automatically load entity data into the internal structure:

var model_file = new A3DAsmModelFileWrapper(model_file_handle);

Memory Management

Wrapper classes implement the IDisposable interface to manage unmanaged resources. To free resources, call Dispose() explicitly:

var model_file = new A3DAsmModelFileWrapper(model_file_handle);

// Use the model file
model_file.Dispose();

Alternatively, use the using statement to ensure automatic disposal:

using (var model_file = new A3DAsmModelFileWrapper(model_file_handle))
{
    // Use the model file
}

For details, see Using objects that implement IDisposable (MSDN).

Properties

Wrapper classes expose fields of data structures as C# Properties:

var model_file = new A3DAsmModelFileWrapper(model_file_handle);

bool unit_from_cad = model_file.m_bUnitFromCAD; // Property get

Properties include both get and set accessors. Array properties are automatically converted to and from unmanaged C-style arrays using C# Array Wrapper. The example below shows how to retrieve a list of child product occurrences as an IntPtr[]:

var product_occurrence = new A3DAsmProductOccurrence(product_occurrence_handle);

IntPtr[] children_handles = product_occurrence.m_ppPOccurrences;

Entity Creation

Wrapper classes provide a Create() method to encapsulate the entity creation process:

var model_file = new A3DAsmModelFileWrapper();

model_file.Create();

Entity Edition

If an entity supports editing, wrapper classes provide an Edit() method:

// ...

model_file.Edit();