Modifies the metric for consuming Sparkplug data by a specified function, for the push data consumption model.
This method always makes the metric writable, including its timestamp, i.e. Sparkplug host applications will be able to modify them. If you need a different behavior, call the Writable(SparkplugMetric,Boolean) method subsequently, with desired parameter, or modify the WritableTimestamp accordingly (set it to true).
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 value that indicates the outcome of the Sparkplug write operation. The WriteFunction(SparkplugMetric,Type,Func<SparkplugData,Boolean>) method overloads are the most generic extensions methods for writing. If you only need to deal with the metric value (and not its timestamp), consider using one of the WriteValueFunction<TValue>(SparkplugMetric,Type,Func<TValue,Boolean>) or WriteValueAction<TValue>(SparkplugMetric,Type,Action<TValue>) method overloads, for shorter code and easier programming.
Makes a metric that consumes the Sparkplug data using the write function. Specify the value type.
Syntax
'Declaration
<ExtensionAttribute()>
<JetBrains.Annotations.NotNullAttribute()>
Public Overloads Shared Function WriteFunction( _
ByVal As SparkplugMetric, _
ByVal As Type, _
ByVal As Func(Of SparkplugData,Boolean) _
) As SparkplugMetric
'Usage
Dim metric As SparkplugMetric
Dim valueType As Type
Dim writeFunction As Func(Of SparkplugData,Boolean)
Dim value As SparkplugMetric
value = SparkplugMetricExtension.WriteFunction(metric, valueType, writeFunction)
[Extension()]
[JetBrains.Annotations.NotNull()]
public static SparkplugMetric WriteFunction(
SparkplugMetric ,
Type ,
Func<SparkplugData,bool>
)
[Extension()]
[JetBrains.Annotations.NotNull()]
public:
static SparkplugMetric^ WriteFunction(
SparkplugMetric^ ,
Type^ ,
Func<SparkplugData^,bool>^
)
Parameters
- metric
- The Sparkplug metric that will perform the operation.
The value of this parameter cannot be null (Nothing in Visual Basic).
- valueType
- The type of the Sparkplug metric, expressed as .NET System.Type.
The value of this parameter cannot be null (Nothing in Visual Basic).
- writeFunction
- The write function, i.e. the function that accepts the Sparkplug data 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).
Return Value
Returns the , internally modified as defined by the method.
This method never returns null (Nothing in Visual Basic).
Exceptions
| Exception | Description |
| System.ArgumentNullException |
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. |
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