# OpcDataObject Members

> Reference: Provides a generic and dynamically accessible representation of structured data types.

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">OpcDataObject</a></dd>
<dt>Namespace</dt>
<dd><a href="../namespaces/opc.uafx">Opc.UaFx</a></dd>
<dt>Assembly</dt>
<dd>Opc.UaFx.Advanced.dll</dd>
<dt>Package</dt>
<dd>Opc.UaFx.Advanced v2.59.0</dd>
<dt>Also in</dt>
<dd>Opc.UaFx.Client</dd>
</dl>

Inherits members from [OpcData](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdata/members).

## Constructors

### OpcDataObject

Initializes a new instance of the [OpcDataObject](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdataobject/) class using the type information of the `dataType` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcDataObject(OpcDataTypeInfo dataType)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(dataType As OpcDataTypeInfo)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `dataType` | [OpcDataTypeInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypeinfo/) | The [OpcDataTypeInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypeinfo/) of the structured data type to represent. |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The `dataType` is not a structured data type (see [IsStruct](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypeinfo/members#isstruct)). |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `dataType` is a null reference (Nothing in Visual Basic). |

## Methods

### GetField

Searches for the field with the specified `name`.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcDataField GetField(string name)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function GetField(name As String) As OpcDataField
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `name` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The [string](https://learn.microsoft.com/dotnet/api/system.string) containing the name of the data field to get. |

**Returns**

[OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/)

An instance of the [OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/) representing the field with the specified name, if found; otherwise a null reference (Nothing in Visual Basic).

**Remarks**

The `name` specified is compared using [Ordinal](https://learn.microsoft.com/dotnet/api/system.stringcomparison#system-stringcomparison-ordinal).

### GetFields

Returns all the fields of the current [OpcDataObject](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdataobject/).

<div class="api-signature" data-lang="csharp">

```csharp
public OpcDataField[] GetFields()
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function GetFields() As OpcDataField()
```

</div>

**Returns**

[OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/)[]

An array of [OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/) objects representing all the fields defined for the current [OpcDataObject](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdataobject/) or an empty array of type [OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/) if no fields are defined for the current [OpcDataObject](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdataobject/).

### GetTypeInfo

Gets the [OpcDataTypeInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypeinfo/) of the current structured data type instance represented.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcDataTypeInfo GetTypeInfo()
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function GetTypeInfo() As OpcDataTypeInfo
```

</div>

**Returns**

[OpcDataTypeInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypeinfo/)

The [OpcDataTypeInfo](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypeinfo/) of the current structured data type instance.

### HasField

Determines whether the current [OpcDataObject](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdataobject/) provides a [OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/) with the [Name](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/members#name) equals to the `name` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public bool HasField(string name)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function HasField(name As String) As Boolean
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `name` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The [string](https://learn.microsoft.com/dotnet/api/system.string) containing the name of the data field to test. |

**Returns**

[Boolean](https://learn.microsoft.com/dotnet/api/system.boolean)

The value true if there exists a [OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/) with the `name` specified; otherwise the value false.

**Remarks**

The `name` specified is compared using [Ordinal](https://learn.microsoft.com/dotnet/api/system.stringcomparison#system-stringcomparison-ordinal).

### TryGetField

Searches for the field associated with the `name` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public bool TryGetField(string name, out OpcDataField field)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function TryGetField(name As String, field As OpcDataField) As Boolean
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `name` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The [string](https://learn.microsoft.com/dotnet/api/system.string) containing the name of the data field to get. |
| `field` | out [OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/) | The [OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/) representing the field with the specified name, if found; otherwise a null reference (Nothing in Visual Basic). |

**Returns**

[Boolean](https://learn.microsoft.com/dotnet/api/system.boolean)

The value true if there exists a [OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/) with the `name` specified (and `field` is set to that field); otherwise the value false.

**Remarks**

The `name` specified is compared using [Ordinal](https://learn.microsoft.com/dotnet/api/system.stringcomparison#system-stringcomparison-ordinal).

## Indexers

### Item

<span class="api-meta">2 overloads</span>

| Overload | Description |
|---|---|
| [this\[int\]](#item-system-int32)<span class="api-meta">since v2.18</span> | Gets the field at the `index` specified. |
| [this\[string\]](#item-system-string) | Gets the field associated with the specified `name`. |

#### this\[int\]

<span class="api-meta">since v2.18</span>

Gets the field at the `index` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcDataField this[int index] { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Default Property this[](index As Integer) As OpcDataField
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `index` | [Int32](https://learn.microsoft.com/dotnet/api/system.int32) | The zero-based index which identifies the data field to get. |

**Property value**

[OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/)

An instance of the [OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/) representing the field at the specified `index`, if existent; otherwise a null reference (Nothing in Visual Basic).

#### this\[string\]

Gets the field associated with the specified `name`.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcDataField this[string name] { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Default Property this[](name As String) As OpcDataField
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `name` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The name of the data field to get. |

**Property value**

[OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/)

An instance of the [OpcDataField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatafield/) representing the field with the specified name, if existent; otherwise a null reference (Nothing in Visual Basic).
