mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 17:23:04 +08:00
Added MqttClientUnsubscribeOptionsBuilder analogous to MqttClientSubscribeOptionsBuilder
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using MQTTnet.Packets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace MQTTnet.Client.Unsubscribing
|
||||
{
|
||||
public class MqttClientUnsubscribeOptionsBuilder
|
||||
{
|
||||
private readonly MqttClientUnsubscribeOptions _unsubscribeOptions = new MqttClientUnsubscribeOptions();
|
||||
|
||||
public MqttClientUnsubscribeOptionsBuilder WithUserProperty(string name, string value)
|
||||
{
|
||||
if (name is null) throw new ArgumentNullException(nameof(name));
|
||||
if (value is null) throw new ArgumentNullException(nameof(value));
|
||||
|
||||
return WithUserProperty(new MqttUserProperty(name, value));
|
||||
}
|
||||
|
||||
public MqttClientUnsubscribeOptionsBuilder WithUserProperty(MqttUserProperty userProperty)
|
||||
{
|
||||
if (userProperty is null) throw new ArgumentNullException(nameof(userProperty));
|
||||
|
||||
if (_unsubscribeOptions.UserProperties is null)
|
||||
{
|
||||
_unsubscribeOptions.UserProperties = new List<MqttUserProperty>();
|
||||
}
|
||||
|
||||
_unsubscribeOptions.UserProperties.Add(userProperty);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MqttClientUnsubscribeOptionsBuilder WithTopicFilter(string topic)
|
||||
{
|
||||
if (topic is null) throw new ArgumentNullException(nameof(topic));
|
||||
|
||||
if (_unsubscribeOptions.TopicFilters is null)
|
||||
{
|
||||
_unsubscribeOptions.TopicFilters = new List<string>();
|
||||
}
|
||||
|
||||
_unsubscribeOptions.TopicFilters.Add(topic);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MqttClientUnsubscribeOptionsBuilder WithTopicFilter(TopicFilter topicFilter)
|
||||
{
|
||||
if (topicFilter is null) throw new ArgumentNullException(nameof(topicFilter));
|
||||
|
||||
return WithTopic(topicFilter.Topic);
|
||||
}
|
||||
|
||||
public MqttClientUnsubscribeOptions Build()
|
||||
{
|
||||
return _unsubscribeOptions;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user