Class ResourceOptions
Definition
- Namespace:
- Tizen.Network.IoTConnectivity
- Assembly:
- Tizen.Network.IoTConnectivity.dll
This class represents resource options. It provides APIs to manage them.
The iotcon options API provides methods for managing vendor specific options of coap packet.
See more about coap packet in http://tools.ietf.org/html/rfc7252.
C#Copypublic class ResourceOptions : IDictionary<ushort, string>, ICollection<KeyValuePair<ushort, string>>, IEnumerable<KeyValuePair<ushort, string>>, IEnumerable, IDisposable
- Inheritance
-
objectResourceOptions
- Implements
-
System.Collections.Generic.IDictionary<TKey, TValue><ushort, string>System.Collections.Generic.ICollection<T><System.Collections.Generic.KeyValuePair<TKey, TValue><ushort, string>>System.Collections.Generic.IEnumerable<T><System.Collections.Generic.KeyValuePair<TKey, TValue><ushort, string>>System.Collections.IEnumerableSystem.IDisposable
Constructors
Declaration
C#Copypublic ResourceOptions()
Examples
CopyResourceOptions options = new ResourceOptions();
Exceptions
| Type | Condition |
|---|---|
| System.NotSupportedException | Thrown when the iotcon is not supported. |
| System.OutOfMemoryException | Thrown when there is not enough memory. |
Properties
Declaration
C#Copypublic int Count { get; }
Property Value
| Type | Description |
|---|---|
| int | The number of options. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data"); options.Add(2055, "sample value"); var count = options.Count; Console.WriteLine("There are {0} keys in the options object", count);
Declaration
C#Copypublic bool IsReadOnly { get; }
Property Value
| Type | Description |
|---|---|
| bool | Whether the collection is readonly. |
Examples
CopyResourceOptions options = new ResourceOptions(); if (options.IsReadOnly) Console.WriteLine("Read only options");
Declaration
C#Copypublic string this[ushort key] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| ushort | key | The option ID to get or set. |
Property Value
| Type | Description |
|---|---|
| string | The option data. |
Examples
CopyResourceOptions options = new ResourceOptions(); options[2055] = "sample-data"; Console.WriteLine("Option has : {0}", options[2055]);
Declaration
C#Copypublic ICollection<ushort> Keys { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.ICollection<T><ushort> | All the Option keys. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data"); options.Add(2055, "sample value"); var keys = options.Keys; Console.WriteLine("Resource options contains keys {0} and {1}", keys.ElementAt(0), keys.ElementAt(1));
Declaration
C#Copypublic ICollection<string> Values { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.ICollection<T><string> | All the Option values. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data"); options.Add(2055, "sample value"); var values = options.Values; Console.WriteLine("Resource options contains values {0} and {1}", values.ElementAt(0), values.ElementAt(1));
Methods
Declaration
C#Copypublic void Add(KeyValuePair<ushort, string> item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.KeyValuePair<TKey, TValue><ushort, string> | item | The key value pair. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "12345"));
See Also
Declaration
C#Copypublic void Add(ushort key, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| ushort | key | The ID of the option to insert. |
| string | value | The string data to insert into the options. |
Remarks
ResourceOptions can have up to 2 options.
key is always situated between 2048 and 3000.
Length of option data is less than or equal to 15.
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data");
Exceptions
| Type | Condition |
|---|---|
| System.NotSupportedException | Thrown when the iotcon is not supported. |
| System.ArgumentException | Thrown when there is an invalid parameter. |
See Also
Declaration
C#Copypublic void Clear()
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "12345"); options.Add(2055, "sample"); options.Clear();
Exceptions
| Type | Condition |
|---|---|
| System.NotSupportedException | Thrown when the iotcon is not supported. |
Declaration
C#Copypublic bool Contains(KeyValuePair<ushort, string> item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.KeyValuePair<TKey, TValue><ushort, string> | item | The key value pair. |
Returns
| Type | Description |
|---|---|
| bool | True if exists. Otherwise, false. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "12345")); var isPresent = options.Contains(new KeyValuePair<ushort, string>(2050, "12345")); if (isPresent) Console.WriteLine("Key value pair is present");
Declaration
C#Copypublic bool ContainsKey(ushort key)
Parameters
| Type | Name | Description |
|---|---|---|
| ushort | key | The key to look for. |
Returns
| Type | Description |
|---|---|
| bool | true if exists. Otherwise, false. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data"); if (options.ContainsKey(2050)) Console.WriteLine("options conatins key : 2050");
CopyTo(KeyValuePair<ushort, string>[], int)
Copies the elements of the options collection to an array, starting at a particular index.
Declaration
C#Copypublic void CopyTo(KeyValuePair<ushort, string>[] array, int arrayIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.KeyValuePair<TKey, TValue><ushort, string>[] | array | The destination array. |
| int | arrayIndex | Index parameter. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "12345")); KeyValuePair<ushort, string>[] dest = new KeyValuePair<ushort, string>[options.Count]; options.CopyTo(dest, 0); Console.WriteLine("Dest conatins ({0}, {1})", dest[0].Key, dest[0].Value);
Declaration
C#Copypublic void Dispose()
Dispose(bool)
Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
Declaration
C#Copyprotected virtual void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | disposing | If true, disposes any disposable objects. If false, does not dispose disposable objects. |
Declaration
C#Copyprotected ~ResourceOptions()
Declaration
C#Copypublic IEnumerator<KeyValuePair<ushort, string>> GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerator<T><System.Collections.Generic.KeyValuePair<TKey, TValue><ushort, string>> | Enumerator to option pairs. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "sample1")); options.Add(new KeyValuePair<ushort, string>(2055, "sample2")); foreach (KeyValuePair<string, object> pair in options) { Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value); }
Declaration
C#Copypublic bool Remove(KeyValuePair<ushort, string> item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.KeyValuePair<TKey, TValue><ushort, string> | item | The key value pair to remove |
Returns
| Type | Description |
|---|---|
| bool | True if operation is successful. Otherwise, false |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "12345")); var result = options.Remove(new KeyValuePair<ushort, string>(2050, "12345"));
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | Thrown when there is an invalid parameter |
See Also
Declaration
C#Copypublic bool Remove(ushort key)
Parameters
| Type | Name | Description |
|---|---|---|
| ushort | key | The ID of the option to delete. |
Returns
| Type | Description |
|---|---|
| bool | True if operation is successful. Otherwise, false. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "12345"); var result = options.Remove(2050);
Exceptions
| Type | Condition |
|---|---|
| System.NotSupportedException | Thrown when the iotcon is not supported. |
| System.ArgumentException | Thrown when there is an invalid parameter. |
See Also
Declaration
C#Copypublic bool TryGetValue(ushort key, out string value)
Parameters
| Type | Name | Description |
|---|---|---|
| ushort | key | The option ID. |
| string | value | Value corresponding to option ID. |
Returns
| Type | Description |
|---|---|
| bool | True if the key exists, false otherwise. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "12345"); string value; var isPresent = options.TryGetValue(2050, out value); if (isPresent) Console.WriteLine("value : {0}", value);
Explicit Interface Implementations
Declaration
C#CopyIEnumerator IEnumerable.GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator | Enumerator to option pairs. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "sample1")); options.Add(new KeyValuePair<ushort, string>(2055, "sample2")); foreach (KeyValuePair<string, object> pair in options) { Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value); }