Class Attributes

Definition

Namespace:
Tizen.Network.IoTConnectivity
Assembly:
Tizen.Network.IoTConnectivity.dll
API Level:
3

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.

C#
Copy
public class Attributes : IDictionary<string, object>, ICollection<KeyValuePair<string, object>>, IEnumerable<KeyValuePair<string, object>>, IEnumerable, IDisposable
Inheritance
System.Object
Attributes
Implements
IDictionary<System.String, System.Object>
System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.String, System.Object>>
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String, System.Object>>
System.IDisposable

Constructors

View Source

Attributes()

The Attributes constructor.

Declaration
C#
Copy
public Attributes()
Examples
Copy
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
Exceptions
Type Condition
System.NotSupportedException

Thrown when the iotcon is not supported.

OutOfMemoryException

Thrown when there is not enough memory.

API Level: 3
Feature: http://tizen.org/feature/iot.ocf

Properties

View Source

Count

Gets the number of keys.

Declaration
C#
Copy
public int Count { get; }
Property Value
Type Description
Int32

The number of keys.

Examples
Copy
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);
API Level: 3
View Source

IsReadOnly

Represents whether an attribute is readonly.

Declaration
C#
Copy
public bool IsReadOnly { get; }
Property Value
Type Description
Boolean

Whether an attribute is readonly.

Examples
Copy
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { { "state", "ON" }, { "dim", 10 } }; if (attributes.IsReadOnly) Console.WriteLine("Read only attribute");
API Level: 3
View Source

Item[String]

Gets or sets the attribute with the specified key.

Declaration
C#
Copy
public object this[string key] { get; set; }
Parameters
Type Name Description
System.String key

The key of the attribute to get or set.

Property Value
Type Description
System.Object

The attribute with the specified key.

Examples
Copy
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes(); attributes["state"] = "ON"; Console.WriteLine("Attribute value for key 'state' : {0}", attributes["state"]);
API Level: 3
View Source

Keys

Contains all the attribute keys.

Declaration
C#
Copy
public ICollection<string> Keys { get; }
Property Value
Type Description
System.Collections.Generic.ICollection<System.String>

All the attribute keys.

Examples
Copy
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));
API Level: 3
View Source

Values

Contains all the attribute values.

Declaration
C#
Copy
public ICollection<object> Values { get; }
Property Value
Type Description
System.Collections.Generic.ICollection<System.Object>

All the attribute values.

Examples
Copy
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));
API Level: 3

Methods

View Source

Add(KeyValuePair<String, Object>)

Adds the attribute key and a value as a key value pair.

Declaration
C#
Copy
public void Add(KeyValuePair<string, object> item)
Parameters
Type Name Description
System.Collections.Generic.KeyValuePair<System.String, System.Object> item

The key value pair to add.

Examples
Copy
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes(); attributes.Add(new KeyValuePair<string, object> ("state", "ON"));
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Add(String, Object)

Adds an attribute.

Declaration
C#
Copy
public void Add(string key, object value)
Parameters
Type Name Description
System.String key

The key representing the attribute.

System.Object value

The value representing the attribute.

Examples
Copy
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes(); attributes.Add("brightness", 50);
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Clear()

Clears attributes collection.

Declaration
C#
Copy
public void Clear()
Examples
Copy
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

API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Contains(KeyValuePair<String, Object>)

Checks whether the given key value pair exists in attributes collection.

Declaration
C#
Copy
public bool Contains(KeyValuePair<string, object> item)
Parameters
Type Name Description
System.Collections.Generic.KeyValuePair<System.String, System.Object> item

The status key value pair.

Returns
Type Description
Boolean

true if exists. Otherwise, false.

Examples
Copy
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)");
API Level: 3
View Source

ContainsKey(String)

Checks whether the given key exists in attributes collection.

Declaration
C#
Copy
public bool ContainsKey(string key)
Parameters
Type Name Description
System.String key

The status key to look for.

Returns
Type Description
Boolean

true if exists. Otherwise, false.

Examples
Copy
Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { { "state", "ON" }, { "dim", 10 } }; if (attributes.ContainsKey("dim")) Console.WriteLine("Attribute conatins key : dim");
API Level: 3
View Source

CopyTo(KeyValuePair<String, Object>[], Int32)

Copies the elements of the attributes to an array, starting at a particular index.

Declaration
C#
Copy
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
Parameters
Type Name Description
System.Collections.Generic.KeyValuePair<System.String, System.Object>[] array

The destination array.

Int32 arrayIndex

The zero-based index in an array at which copying begins.

Examples
Copy
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);
API Level: 3
View Source

Dispose()

Releases any unmanaged resources used by this object.

Declaration
C#
Copy
public void Dispose()
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Dispose(Boolean)

Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.

Declaration
C#
Copy
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing

If true, disposes any disposable objects. If false, does not dispose disposable objects.

API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Finalize()

Destructor of the Attributes class.

Declaration
C#
Copy
protected void Finalize()
View Source

GetEnumerator()

Returns an enumerator that iterates through the collection.

Declaration
C#
Copy
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<System.String, System.Object>>

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

Examples
Copy
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); }
API Level: 3
View Source

Remove(KeyValuePair<String, Object>)

Removes an attribute from collection.

Declaration
C#
Copy
public bool Remove(KeyValuePair<string, object> item)
Parameters
Type Name Description
System.Collections.Generic.KeyValuePair<System.String, System.Object> item

The attributes element to remove.

Returns
Type Description
Boolean

true if operation is successful, otherwise, false.

Examples
Copy
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

API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Remove(String)

Removes an attribute from collection using a key.

Declaration
C#
Copy
public bool Remove(string key)
Parameters
Type Name Description
System.String key

The attributes element to remove.

Returns
Type Description
Boolean

true if operation is successful, otherwise, false.

Examples
Copy
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

API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

TryGetValue(String, out Object)

Gets the value associated with the specified key.

Declaration
C#
Copy
public bool TryGetValue(string key, out object value)
Parameters
Type Name Description
System.String key

The key whose value to get.

System.Object value

The value associated with the specified key.

Returns
Type Description
Boolean

true if the attributes collection contains an element with the specified key, otherwise, false.

Examples
Copy
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);
API Level: 3

Explicit Interface Implementations

View Source

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through the collection.

Declaration
C#
Copy
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator
API Level: 3

Implements

System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
System.IDisposable