UserPropertyExtension.cs 604 B

12345678910111213141516
  1. using System;
  2. using System.Linq;
  3. namespace MQTTnet.Extensions
  4. {
  5. public static class UserPropertyExtension
  6. {
  7. public static string GetUserProperty(this MqttApplicationMessage message, string propertyName, StringComparison comparisonType = StringComparison.Ordinal)
  8. {
  9. if (message == null) throw new ArgumentNullException(nameof(message));
  10. if (propertyName == null) throw new ArgumentNullException(nameof(propertyName));
  11. return message.UserProperties?.SingleOrDefault(up => up.Name.Equals(propertyName, comparisonType))?.Value;
  12. }
  13. }
  14. }