Connectivity Software User's Guide and Reference
WriteValueFunction<TValue>(SparkplugMetric,Type,Func<TValue,Boolean>) Method



OpcLabs.EasySparkplug Assembly > OpcLabs.EasySparkplug Namespace > SparkplugMetricExtension Class > WriteValueFunction Method : WriteValueFunction<TValue>(SparkplugMetric,Type,Func<TValue,Boolean>) Method
The type of the value of the Sparkplug metric.
The Sparkplug metric that will perform the operation.

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

The declared type of the Sparkplug metric, expressed as .NET System.Type.

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

The write value function, i.e. the function that accepts the value to be written, performs the write operation, and returns a boolean success indication.

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

Modifies the metric for consuming values by a specified function, for the push data consumption model.

This method always makes the metric writable; however, its timestamp will not be writable, i.e. Sparkplug host application will not be able to modify them. If you need a different behavior, use one of the WriteFunction(SparkplugMetric,Type,Func<SparkplugData,Boolean>) method overloads instead.

This method does not change the readability access of the metric. By default, metrics are readable. If you need a metric that is writable but non-readable, combine this method with calling Readable(SparkplugMetric,Boolean) method with the 'readable' parameter set to false.

The write function returns a boolean that indicates the outcome of the Sparkplug write operation. If the outcome of your write operation should always be successful, you can make your code a bit simpler by using one of WriteValueAction<TValue>(SparkplugMetric,Type,Action<TValue>) method overloads instead.

Makes a metric that consumes the Sparkplug data using the write value function. Specify the declared type.
Syntax
'Declaration
 
<ExtensionAttribute()>
<JetBrains.Annotations.NotNullAttribute()>
Public Overloads Shared Function WriteValueFunction(Of TValue)( _
   ByVal metric As SparkplugMetric, _
   ByVal declaredType As Type, _
   ByVal writeValueFunction As Func(Of TValue,Boolean) _
) As SparkplugMetric
'Usage
 
Dim metric As SparkplugMetric
Dim declaredType As Type
Dim writeValueFunction As Func(Of TValue,Boolean)
Dim value As SparkplugMetric
 
value = SparkplugMetricExtension.WriteValueFunction(Of TValue)(metric, declaredType, writeValueFunction)
[Extension()]
[JetBrains.Annotations.NotNull()]
public static SparkplugMetric WriteValueFunction<TValue>( 
   SparkplugMetric metric,
   Type declaredType,
   Func<TValue,bool> writeValueFunction
)
[Extension()]
[JetBrains.Annotations.NotNull()]
public:
static SparkplugMetric^ WriteValueFunctiongeneric<typename TValue>
( 
   SparkplugMetric^ metric,
   Type^ declaredType,
   Func<TValue^,bool>^ writeValueFunction
) 

Parameters

metric
The Sparkplug metric that will perform the operation.

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

declaredType
The declared type of the Sparkplug metric, expressed as .NET System.Type.

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

writeValueFunction
The write value function, i.e. the function that accepts the value to be written, performs the write operation, and returns a boolean success indication.

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

Type Parameters

TValue
The type of the value of the Sparkplug metric.

Return Value

Returns the metric, internally modified as defined by the method.

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

Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

This method always makes the metric writable; however, its timestamp will not be writable, i.e. Sparkplug host application will not be able to modify them. If you need a different behavior, use one of the WriteFunction(SparkplugMetric,Type,Func<SparkplugData,Boolean>) method overloads instead.

This method does not change the readability access of the metric. By default, metrics are readable. If you need a metric that is writable but non-readable, combine this method with calling Readable(SparkplugMetric,Boolean) method with the 'readable' parameter set to false.

The write function returns a boolean that indicates the outcome of the Sparkplug write operation. If the outcome of your write operation should always be successful, you can make your code a bit simpler by using one of WriteValueAction<TValue>(SparkplugMetric,Type,Action<TValue>) method overloads instead.

This method overload infers the Sparkplug data type the metric from the declaredType parameter. The type used in your code to implement the metric behavior can be different, and it will be TValue. The toolkit provides automatic value conversions. This can be useful in case your language makes it more difficult to process some .NET types, as is the case e.g. with VB.NET and unsigned integer types such as System.UInt32. In this case, for example, if you want a metric of Sparkplug type UInt32, you can set declaredType to System.UInt32, but use an System.Int64 as the return type of your function (TValue).

This is an extension method (info: C#, VB.NET). In languages that have support for extensions methods (such as C# and VB.NET), you can use the extension method as if it were a regular method on the object that is its first parameter. In other languages (such as with Python.NET), you will call the extension as a static method, and pass it the object on which it acts as its first parameter.

 

Sparkplug is a trademark of Eclipse Foundation, Inc. "MQTT" is a trademark of the OASIS Open standards consortium. Other related terms are trademarks of their respective owners. Any use of these terms on this site is for descriptive purposes only and does not imply any sponsorship, endorsement or affiliation.

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