Class Attributes
Definition
- Namespace:
- Tizen.Network.IoTConnectivity
- Assembly:
- Tizen.Network.IoTConnectivity.dll
This class represents current attributes of a resource. It provides API to manage attributes. This class is accessed by using a constructor to create a new instance of this object.
public class Attributes : IDictionary<string, object>, ICollection<KeyValuePair<string, object>>, IEnumerable<KeyValuePair<string, object>>, IEnumerable, IDisposable
- Inheritance
-
objectAttributes
- Implements
-
System.Collections.Generic.IDictionary<TKey, TValue><string, object>System.Collections.Generic.ICollection<T><System.Collections.Generic.KeyValuePair<TKey, TValue><string, object>>System.Collections.Generic.IEnumerable<T><System.Collections.Generic.KeyValuePair<TKey, TValue><string, object>>System.Collections.IEnumerableSystem.IDisposable
Constructors
View SourceAttributes()
The Attributes constructor.
Declaration
public Attributes()
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Thrown when the iotcon is not supported. |
System.OutOfMemoryException | Thrown when there is not enough memory. |
Properties
View SourceCount
Gets the number of keys.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int | The number of keys. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
attributes.Add("brightness", 50);
var count = attributes.Count;
Console.WriteLine("There are {0} keys in the attribute object", count);
View Source
IsReadOnly
Represents whether an attribute is readonly.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
bool | Whether an attribute is readonly. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
{ "state", "ON" },
{ "dim", 10 }
};
if (attributes.IsReadOnly)
Console.WriteLine("Read only attribute");
View Source
this[string]
Gets or sets the attribute with the specified key.
Declaration
public object this[string key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the attribute to get or set. |
Property Value
Type | Description |
---|---|
object | The attribute with the specified key. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
attributes["state"] = "ON";
Console.WriteLine("Attribute value for key 'state' : {0}", attributes["state"]);
View Source
Keys
Contains all the attribute keys.
Declaration
public ICollection<string> Keys { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<T><string> | All the attribute keys. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
{ "state", "ON" },
{ "dim", 10 }
};
var keys = attributes.Keys;
Console.WriteLine("Attribute contains keys {0} and {1}", keys.ElementAt(0), keys.ElementAt(1));
View Source
Values
Contains all the attribute values.
Declaration
public ICollection<object> Values { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<T><object> | All the attribute values. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
{ "state", "ON" },
{ "dim", 10 }
};
var values = attributes.Values;
Console.WriteLine("Attribute contains values {0} and {1}", values.ElementAt(0), values.ElementAt(1));
Methods
View SourceAdd(KeyValuePair<string, object>)
Adds the attribute key and a value as a key value pair.
Declaration
public void Add(KeyValuePair<string, object> item)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue><string, object> | item | The key value pair to add. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
attributes.Add(new KeyValuePair<string, object> ("state", "ON"));
View Source
Add(string, object)
Adds an attribute.
Declaration
public void Add(string key, object value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key representing the attribute. |
object | value | The value representing the attribute. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
attributes.Add("brightness", 50);
View Source
Clear()
Clears attributes collection.
Declaration
public void Clear()
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
attributes.Add("brightness", 50);
attributes.Clear();
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Thrown when the iotcon is not supported |
System.InvalidOperationException | Thrown when the operation is invalid |
Contains(KeyValuePair<string, object>)
Checks whether the given key value pair exists in attributes collection.
Declaration
public bool Contains(KeyValuePair<string, object> item)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue><string, object> | item | The status key value pair. |
Returns
Type | Description |
---|---|
bool | true if exists. Otherwise, false. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
{ "state", "ON" },
{ "dim", 10 }
};
if (attributes.Contains(new KeyValuePair<string, object> ("dim", 10))
Console.WriteLine("Attribute conatins pair ('dim', 10)");
View Source
ContainsKey(string)
Checks whether the given key exists in attributes collection.
Declaration
public bool ContainsKey(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The status key to look for. |
Returns
Type | Description |
---|---|
bool | true if exists. Otherwise, false. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
{ "state", "ON" },
{ "dim", 10 }
};
if (attributes.ContainsKey("dim"))
Console.WriteLine("Attribute conatins key : dim");
View Source
CopyTo(KeyValuePair<string, object>[], int)
Copies the elements of the attributes to an array, starting at a particular index.
Declaration
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue><string, object>[] | array | The destination array. |
int | arrayIndex | The zero-based index in an array at which copying begins. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
{ "state", "ON" },
{ "dim", 10 }
};
KeyValuePair<string, object>[] dest = new KeyValuePair<string, object>[attributes.Count];
int index = 0;
attributes.CopyTo(dest, index);
Console.WriteLine("Dest conatins ({0}, {1})", dest[0].Key, dest[0].Value);
View Source
Dispose()
Releases any unmanaged resources used by this object.
Declaration
public void Dispose()
Dispose(bool)
Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | If true, disposes any disposable objects. If false, does not dispose disposable objects. |
~Attributes()
Destructor of the Attributes class.
Declaration
protected ~Attributes()
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<T><System.Collections.Generic.KeyValuePair<TKey, TValue><string, object>> | An enumerator that can be used to iterate through the collection. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
{ "state", "ON" },
{ "dim", 10 }
};
foreach (KeyValuePair<string, object> pair in attributes)
{
Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value);
}
View Source
Remove(KeyValuePair<string, object>)
Removes an attribute from collection.
Declaration
public bool Remove(KeyValuePair<string, object> item)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue><string, object> | item | The attributes element to remove. |
Returns
Type | Description |
---|---|
bool | true if operation is successful, otherwise, false. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
{ "state", "ON" },
{ "dim", 10 }
};
if (attributes.Remove(new KeyValuePair<string, object>("dim", 10)))
Console.WriteLine("Remove was successful");
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Thrown when the iotcon is not supported |
System.ArgumentException | Thrown when there is an invalid parameter |
System.InvalidOperationException | Thrown when the operation is invalid |
Remove(string)
Removes an attribute from collection using a key.
Declaration
public bool Remove(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The attributes element to remove. |
Returns
Type | Description |
---|---|
bool | true if operation is successful, otherwise, false. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
{ "state", "ON" },
{ "dim", 10 }
};
if (attributes.Remove("state"))
Console.WriteLine("Remove was successful");
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Thrown when the iotcon is not supported |
System.ArgumentException | Thrown when there is an invalid parameter |
System.InvalidOperationException | Thrown when the operation is invalid |
TryGetValue(string, out object)
Gets the value associated with the specified key.
Declaration
public bool TryGetValue(string key, out object value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key whose value to get. |
object | value | The value associated with the specified key. |
Returns
Type | Description |
---|---|
bool | true if the attributes collection contains an element with the specified key, otherwise, false. |
Examples
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
{ "state", "ON" }
};
object value;
var isPresent = attributes.TryGetValue("state", out value);
if (isPresent)
Console.WriteLine("value : {0}", value);
Explicit Interface Implementations
View SourceIEnumerable.GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator |