Table of Contents

Class AttributedReadings

Namespace
Acuit.Pinpoint.IO.Testing.DataAnnotations
Assembly
Acuit.Pinpoint.IO.Testing.Abstractions.dll

The base class for a type that contains readings defined via reading annotation attributes (e.g., NumericReadingAttribute).

public abstract class AttributedReadings : IReadingCollection, IReadOnlyDictionary<string, IReadingValue>, IReadOnlyCollection<KeyValuePair<string, IReadingValue>>, IEnumerable<KeyValuePair<string, IReadingValue>>, IEnumerable
Inheritance
AttributedReadings
Implements
Inherited Members
Extension Methods

Remarks

To use this method of defining readings:

  1. Define a custom class that derives from this class (e.g., MyAttributedReadingsClass).
  2. Apply NumericReadingAttribute to the public properties that expose reading values.
  3. In the device class, implement IPolledReadingsProvider, where:
    1. ReadingDescriptors can be implemented via GetReadingDescriptorsForAttributedType(Type). For example:
      public IReadingDescriptorCollection ReadingDescriptors { get; } = AttributedReadings.GetReadingDescriptorsForAttributedType(typeof(MyAttributedReadingsClass));
      
    2. ReadValuesAsync(CancellationToken) should read the values and return an instance of the readings class (e.g., MyAttributedReadingsClass).
  4. Register the reading provider via IReadingsRegistry.RegisterPolledProvider(IPolledReadingsProvider), typically in the device class constructor, being sure to unregister it when the device instance is disposed.

Constructors

AttributedReadings()

Initializes a new instance of the AttributedReadings class.

protected AttributedReadings()

Properties

Count

Gets the number of elements in the collection.

public int Count { get; }

Property Value

int

The number of elements in the collection.

this[string]

Gets the element that has the specified key in the read-only dictionary.

public IReadingValue this[string key] { get; }

Parameters

key string

The key to locate.

Property Value

IReadingValue

The element that has the specified key in the read-only dictionary.

Exceptions

ArgumentNullException

key is null.

KeyNotFoundException

The property is retrieved and key is not found.

Keys

Gets an enumerable collection that contains the keys in the read-only dictionary.

public IEnumerable<string> Keys { get; }

Property Value

IEnumerable<string>

An enumerable collection that contains the keys in the read-only dictionary.

Values

Gets an enumerable collection that contains the values in the read-only dictionary.

public IEnumerable<IReadingValue> Values { get; }

Property Value

IEnumerable<IReadingValue>

An enumerable collection that contains the values in the read-only dictionary.

Methods

ContainsKey(string)

Determines whether the read-only dictionary contains an element that has the specified key.

public bool ContainsKey(string key)

Parameters

key string

The key to locate.

Returns

bool

true if the read-only dictionary contains an element that has the specified key; otherwise, false.

Exceptions

ArgumentNullException

key is null.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<KeyValuePair<string, IReadingValue>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<string, IReadingValue>>

An enumerator that can be used to iterate through the collection.

GetReadingDescriptorsForAttributedType(Type)

Gets the ReadingDescriptorCollection instance for a type containing properties annotated with reading annotation attributes.

public static ReadingDescriptorCollection GetReadingDescriptorsForAttributedType(Type type)

Parameters

type Type

The type that contains properties annotated with reading annotation attributes.

Returns

ReadingDescriptorCollection

The ReadingDescriptorCollection instance for the type. This will only be generated once per type.

Exceptions

ArgumentNullException

type is null.

InvalidOperationException

The specified type does not contain any properties annotated with reading annotation attributes.

InvalidOperationException

A property on the specified type cannot be used as a reading value.

TryGetValue(string, out IReadingValue)

Gets the value that is associated with the specified key.

public bool TryGetValue(string key, out IReadingValue value)

Parameters

key string

The key to locate.

value IReadingValue

When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

Returns

bool

true if the object that implements the IReadOnlyDictionary<TKey, TValue> interface contains an element that has the specified key; otherwise, false.

Exceptions

ArgumentNullException

key is null.