# OpcDataTypeMemberLengthAttribute Members

> Reference: Declares a field or property of a custom data type, to that the member belongs on that this attribute is applied, with a variable or fixed length of the member within the stream of its custom data type.

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">OpcDataTypeMemberLengthAttribute</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 [Attribute](https://learn.microsoft.com/dotnet/api/system.attribute).

## Constructors

### OpcDataTypeMemberLengthAttribute

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

| Overload | Description |
|---|---|
| [OpcDataTypeMemberLengthAttribute(long)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/members#opcdatatypememberlengthattribute-system-int64) | Initializes a new instance of the [OpcDataTypeMemberLengthAttribute](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/) class which declares a field or property with a fixed length. |
| [OpcDataTypeMemberLengthAttribute(string)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/members#opcdatatypememberlengthattribute-system-string) | Initializes a new instance of the [OpcDataTypeMemberLengthAttribute](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/) class which declares a field or property with a variable length controlled by the value of a preceding field or property which can be identified by the `name` specified. |

#### OpcDataTypeMemberLengthAttribute(long)

Initializes a new instance of the [OpcDataTypeMemberLengthAttribute](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/) class which declares a field or property with a fixed length.

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

```csharp
public OpcDataTypeMemberLengthAttribute(long length)
```

</div>

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

```vbnet
Public Sub New(length As Long)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `length` | [Int64](https://learn.microsoft.com/dotnet/api/system.int64) | The total number of instances within the stream of the custom data type of the member the attribute belongs to. |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception) | The `length` is less than zero. |

#### OpcDataTypeMemberLengthAttribute(string)

Initializes a new instance of the [OpcDataTypeMemberLengthAttribute](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/) class which declares a field or property with a variable length controlled by the value of a preceding field or property which can be identified by the `name` specified.

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

```csharp
public OpcDataTypeMemberLengthAttribute(string name)
```

</div>

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

```vbnet
Public Sub New(name As String)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `name` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The [Name](https://learn.microsoft.com/dotnet/api/system.reflection.memberinfo.name) or [Name](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberattribute/members#name) (if defined) of the preceding member its value is to be used to indicate the variable length of the member the attribute belongs to. |

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The `name` is an empty string. |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `name` is a null reference (Nothing in Visual Basic). |

## Properties

### Length

Gets the total number of instances within the stream of the custom data type of the member the attribute belongs to.

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

```csharp
public long Length { get; }
```

</div>

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

```vbnet
Public ReadOnly Property Length As Long
```

</div>

**Property value**

[Int64](https://learn.microsoft.com/dotnet/api/system.int64)

The total number of instances within the stream. The default value is -1. In case there the value of the [Length](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/members#length) property is equals -1 the length of the field or property is variable and determined using the value of the field referenced by [Name](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/members#name).

### Name

Gets the name of the preceding member its value is to be evaluated to indicate the variable length of the member the attribute belongs to.

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

```csharp
public string Name { get; }
```

</div>

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

```vbnet
Public ReadOnly Property Name As String
```

</div>

**Property value**

[String](https://learn.microsoft.com/dotnet/api/system.string)

The [Name](https://learn.microsoft.com/dotnet/api/system.reflection.memberinfo.name) or [Name](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberattribute/members#name) (if defined) of the preceding member or a null reference (Nothing in Visual Basic) in case there this [OpcDataTypeMemberLengthAttribute](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/) uses a fixed [Length](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/members#length) to define the total number of instances within the stream.

**Remarks**

In case there [Name](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/members#name) referes to a field that is not present in an encoded value, then the default value for the length is 1. This situation can occur if the the field referenced is an optional field (see [OpcDataTypeMemberSwitchAttribute](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberswitchattribute/)).

The length field shall be a fixed length Base-2 representation of an integer. If the length field is one of the standard signed integer types and the value is a negative integer, then the field is not present in the encoded stream. The field referenced by the [Name](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/members#name) shall precede the field with the custom data type.

## Methods

### GetLength

Retrieves the [OpcMemberLength](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcmemberlength/) defined by the [OpcDataTypeMemberLengthAttribute](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcdatatypememberlengthattribute/).

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

```csharp
public OpcMemberLength GetLength()
```

</div>

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

```vbnet
Public Function GetLength() As OpcMemberLength
```

</div>

**Returns**

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

A new [OpcMemberLength](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcmemberlength/) instance which provides the information required to determine the length of the member the attribute belongs to.
