Connectivity Software User's Guide and Reference
ToOptionalAttributeValueResult<TValue> Method



OpcLabs.EasyOpcUAPrimitives Assembly > OpcLabs.EasyOpc.UA.OperationModel Namespace > UAAttributeDataResult Class : ToOptionalAttributeValueResult<TValue> Method
The target type for the value.
A function to transform exceptions before including them in the result.

The value of this parameter cannot be null (Nothing in Visual Basic).

Converts this attribute data result to a strongly-typed OpcLabs.BaseLib.OperationModel.Generic.ValueResult<T>, treating BadAttributeIdInvalid status as success with a default value.
Syntax
'Declaration
 
<JetBrains.Annotations.NotNullAttribute()>
Public Function ToOptionalAttributeValueResult(Of TValue)( _
   ByVal exceptionTransformingFunction As Func(Of Exception,Exception) _
) As ValueResult(Of TValue)
'Usage
 
Dim instance As UAAttributeDataResult
Dim exceptionTransformingFunction As Func(Of Exception,Exception)
Dim value As ValueResult(Of TValue)
 
value = instance.ToOptionalAttributeValueResult(Of TValue)(exceptionTransformingFunction)
[JetBrains.Annotations.NotNull()]
public ValueResult<TValue> ToOptionalAttributeValueResult<TValue>( 
   Func<Exception,Exception> exceptionTransformingFunction
)
[JetBrains.Annotations.NotNull()]
public:
ValueResult<TValue^>^ ToOptionalAttributeValueResultgeneric<typename TValue>
( 
   Func<Exception^,Exception^>^ exceptionTransformingFunction
) 

Parameters

exceptionTransformingFunction
A function to transform exceptions before including them in the result.

The value of this parameter cannot be null (Nothing in Visual Basic).

Type Parameters

TValue
The target type for the value.

Return Value

A strongly-typed OpcLabs.BaseLib.OperationModel.Generic.ValueResult<T>. Returns success with default value if the status is BadAttributeIdInvalid.

This method never returns null (Nothing in Visual Basic).

Remarks

This method is useful for optional attributes that may not exist. If the status code is BadAttributeIdInvalid, it returns a successful result with the default value for TValue. Otherwise, it behaves like ToGoodValueResult<TValue>(Func<Exception,Exception>).

This method or property does not throw any exceptions, aside from execution exceptions such as System.Threading.ThreadAbortException or System.OutOfMemoryException.

Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also