Class PlugExtraData
[Obfuscation(Exclude = true, ApplyToMembers = true)]
[Serializable]
public class PlugExtraData
Inheritance
Inherited Members
Namespace: HomeSeer.PluginSdk.Devices
Assembly: PluginSdk.dll
A collection of keyed and non-keyed data items attached to an AbstractHsDevice
Remarks
Use this to store any data specific to the operation of your plugin.
Please note that all keys will be converted to lower case when stored in the HS database
Fields
View Source_namedData
Declaration
Dictionary<string, string> _namedData
Field Value
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.String, System.String> |
_unNamedData
Declaration
List<string> _unNamedData
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<System.String> |
Properties
View SourceItem[Int32]
Access the non-keyed item located at the specified index in the collection.
Declaration
public string this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the non-keyed item. |
Property Value
Type | Description |
---|---|
System.String |
Remarks
This returns the value as is.
See Also
View SourceItem[String]
Access the item with the specified key
Declaration
public string this[string key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key of the item |
Property Value
Type | Description |
---|---|
System.String |
Remarks
This returns the value as is.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when the specified key is null or whitespace. |
See Also
View SourceNamedCount
The number of keyed data items stored in the PlugExtraData
Declaration
public int NamedCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
NamedKeys
A list of keys for data items stored in this PlugExtraData
Declaration
public List<string> NamedKeys { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<System.String> |
UnNamed
A collection of non-keyed data items stored in the PlugExtraData
Declaration
public List<string> UnNamed { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<System.String> |
Remarks
Use Item[Int32] or GetUnNamed(Int32) to retrieve the value as is. If the stored value is a JSON string, use GetUnNamed<TData>(Int32) to retrieve the value while using Newtonsoft to deserialize it.
UnNamedCount
The number of non-keyed items in the PlugExtraData
Declaration
public int UnNamedCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
View SourceAddNamed(String, String)
Add a new keyed data item to the collection
Declaration
public bool AddNamed(string key, string data)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key for the data |
System.String | data | The data to save |
Returns
Type | Description |
---|---|
System.Boolean | TRUE if the item was saved, FALSE if it already exists |
Remarks
If you are trying to store an object, serialize it as a string using Newtonsoft before saving it or use AddNamed<TData>(String, TData). Do not serialize primitives. Serializing primitives may produce unintended results.
Please note that all keys will be converted to lower case when stored in the HS database
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when the key is null or whitespace |
AddNamed<TData>(String, TData)
Add a new keyed data item to the collection. Serialize the data
to a string before saving.
Declaration
public bool AddNamed<TData>(string key, TData data)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key for the data |
TData | data | The data to save in the collection of type |
Returns
Type | Description |
---|---|
System.Boolean | TRUE if the item was saved, FALSE if it already exists |
Type Parameters
Name | Description |
---|---|
TData | The type of the |
Remarks
Please note that all keys will be converted to lower case when stored in the HS database
Do not serialize primitives. Serializing primitives may produce unintended results. Use AddNamed(String, String) to save primitive values.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when the key or data is null |
JsonDataException | Thrown when there is an error while serializing the data |
AddUnNamed(String)
Add a new item to the collection without a key.
Declaration
public int AddUnNamed(string data)
Parameters
Type | Name | Description |
---|---|---|
System.String | data | The data for the item to save. |
Returns
Type | Description |
---|---|
System.Int32 | The index of the item in the collection. |
Remarks
If you are trying to store an object, serialize it as a string using Newtonsoft before saving it or use AddUnNamed<TData>(TData). Do not serialize primitives. Serializing primitives may produce unintended results.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when the data to be stored is null or whitespace. |
AddUnNamed<TData>(TData)
Add a new item to the collection without a key. Serialize the data
to a string before saving.
Declaration
public int AddUnNamed<TData>(TData data)
Parameters
Type | Name | Description |
---|---|---|
TData | data | The data to save in the collection of type |
Returns
Type | Description |
---|---|
System.Int32 | The index of the item in the collection. |
Type Parameters
Name | Description |
---|---|
TData | The type of the |
Remarks
Do not serialize primitives. Serializing primitives may produce unintended results. Use AddUnNamed(String) to save primitive values.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when the data is null |
JsonDataException | Thrown when there is an error while serializing the data |
See Also
View SourceContainsNamed(String)
Determine if a data item with the specified key exists in the collection
Declaration
public bool ContainsNamed(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key of the data item to look for |
Returns
Type | Description |
---|---|
System.Boolean | TRUE if the item exists in the collection, FALSE if it does not. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when the specified key is null or whitespace. |
GetNamed(String)
Get the item with the specified key. This does not process the data at all. It returns the value as it is stored.
Declaration
public string GetNamed(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key of the item to get |
Returns
Type | Description |
---|---|
System.String | The string represented by the specified |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when the specified key is null or whitespace. |
See Also
View SourceGetNamed<TData>(String)
Get the item with the specified key deserialized as the specified type. To retrieve the value without deserializing it, use Item[String] or GetNamed(String)
Declaration
public TData GetNamed<TData>(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key of the item to get |
Returns
Type | Description |
---|---|
TData | The data stored at the specified key as an instance of the specified object type |
Type Parameters
Name | Description |
---|---|
TData | The type of the object stored as a JSON serialized string |
Remarks
This method uses Newtonsoft to deserialize the value to the type specified by TData
.
Do not use this to deserialize primitives.
Exceptions
Type | Condition |
---|---|
JsonDataException | Thrown when there was a problem deserializing the data |
System.ArgumentNullException | Thrown when the specified key is null or whitespace. |
See Also
View SourceGetUnNamed(Int32)
Get the non-keyed item located at the specified index in the collection. This does not process the data at all. It returns the value as it is stored.
Declaration
public string GetUnNamed(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the non-keyed item to get. |
Returns
Type | Description |
---|---|
System.String |
Exceptions
Type | Condition |
---|---|
System.IndexOutOfRangeException | Thrown if the |
See Also
View SourceGetUnNamed<TData>(Int32)
Get the non-keyed item located at the specified index in the collection deserialized to the specified type. Use Item[Int32] or GetUnNamed(Int32) to retrieve the value as is.
Declaration
public TData GetUnNamed<TData>(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the non-keyed item to get. |
Returns
Type | Description |
---|---|
TData | An instance of the specified type of the data at the specified index in the collection. |
Type Parameters
Name | Description |
---|---|
TData | The type the data should be deserialized to. |
Remarks
This method uses Newtonsoft to deserialize the value to the type specified by TData
.
Do not use this to deserialize primitives.
Exceptions
Type | Condition |
---|---|
JsonDataException | Thrown when there is an error deserializing the data to the type specified. |
See Also
View SourceRemoveAllNamed()
Remove all keyed items from the collection.
Declaration
public void RemoveAllNamed()
RemoveAllUnNamed()
Remove all non-keyed items from the collection.
Declaration
public void RemoveAllUnNamed()
RemoveNamed(String)
Remove the data item with the specified key from the collection.
Declaration
public bool RemoveNamed(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key of the data item to remove |
Returns
Type | Description |
---|---|
System.Boolean | TRUE if the item was removed from the collection, FALSE if it was not. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when the specified key is null or whitespace. |
RemoveUnNamed(String)
Remove the specified non-keyed item from the collection using the default Equals implementation of the strings.
Declaration
public bool RemoveUnNamed(string data)
Parameters
Type | Name | Description |
---|---|---|
System.String | data | The non-keyed item to remove from the collection. |
Returns
Type | Description |
---|---|
System.Boolean | TRUE if the item was removed, FALSE if it wasn't. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when the specified data is null or an empty string. |
RemoveUnNamedAt(Int32)
Remove the non-keyed item at the specified index from the collection.
Declaration
public void RemoveUnNamedAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the non-keyed item to remove from the collection. |