Exemple #1
0
        /// <inheritdoc />
        public string ToString([NotNull] CharacteristicBase characteristic)
        {
            Guard.ArgumentNotNull(characteristic,
                                  nameof(characteristic));

            var builder = new StringBuilder( );

            builder.AppendLine($"{characteristic.GetType ( ).Name}");

            foreach (var key in characteristic.DescriptionToUuid.Keys)
            {
                var value = TryGetValueOrEmpty(characteristic,
                                               key);

                var rawValueOrUnavailable = RawValueOrUnavailable(characteristic,
                                                                  key,
                                                                  value);

                builder.Append(rawValueOrUnavailable);

                if (characteristic.Characteristics.Properties.TryGetValue(key,
                                                                          out var properties)
                    )
                {
                    builder.AppendLine($" ({properties.ToCsv ( )})");
                }
                else
                {
                    builder.AppendLine( );
                }
            }

            return(builder.ToString( ));
        }
Exemple #2
0
 protected IEnumerable <byte> TryGetValueOrEmpty(CharacteristicBase characteristic,
                                                 string key)
 {
     return(characteristic.RawValues.TryGetValue(key,
                                                 out var values)
                ? values
                : RawArrayEmpty);
 }
Exemple #3
0
 protected string RawValueOrUnavailable(CharacteristicBase characteristic,
                                        string key,
                                        IEnumerable <byte> value)
 {
     return(characteristic.Characteristics.Characteristics
            .ContainsKey(key)
                ? $"{key} = [{value.ToHex ( )}]"
                : $"{key} = Unavailable");
 }